htmlpurifier
htmlpurifier copied to clipboard
Image Style Percentage
Why are image style height percentage stripped but not for pixels?
Input
<img class="img-fluid" src="/storage/uploads/abc.jpeg" alt="abc.jpeg" style="width: 25%;">
Output
<img class="img-fluid" src="/storage/uploads/abc.jpeg" alt="abc.jpeg">
I've configured my settings as follows, including style within img[]
'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src|class|style]',
If I pass the height and width as pixels, it works as expected.
Thanks
Looks like by default sizes can only be fixed values. You can disable the pixels check with something like this:
[
'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[alt|src|style],code,pre',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,width,max-width',
// This config option allows for b64 & regular linked images
'URI.AllowedSchemes' => ['data' => true,'src'=>true,'http' => true, 'https' => true,],
// This config option disables the pixel checks
'HTML.MaxImgLength' => NULL,
'CSS.MaxImgLength' => NULL,
]
I try this case, and this is don't work. Input:
<img src="<some_correct_uri>" alt="5cd85f1bb85ad.jpg" style="float: none; width: 50%;">
Output:
<img src="<same_correct_uri>" alt="5cd85f1bb85ad.jpg">
And my config:
['Cache.DefinitionImpl' => null,
'HTML.Doctype' => 'HTML 4.01 Transitional',
'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[style|width|height|alt|src|data-filename],h1,h2,h3,h4,h5,h6,sup,sub,strike,pre,blockquote',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,width,height',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
'HTML.MaxImgLength' => null,
'CSS.MaxImgLength' => null,
]