ErikHen / PictureRenderer.Optimizely

PictureRenderer for Optimizely CMS (former Episerver)
MIT License
13 stars 4 forks source link

RenderXhtmlString has a bug with svg images that are added to the xhtmlstring property #18

Closed nguyejon-te closed 10 months ago

nguyejon-te commented 11 months ago

Our customer adds different images to the property and in case of the svg adds different attributes related to the size of the image such as: <img src="/EPiServer/CMS/Content/globalassets/svgimage.svg,,20247?epieditmode=false" alt="something" width="200" height="41">

When these images are processed using the RenderXhtmlString method the image tags become: <picture><source srcset="/globalassets/svgimage.svg?width=200&height=41&quality=80 200w"><img alt="something" src="/globalassets/svgimage.svg?width=200&height=41&quality=80" loading="lazy" decoding="async"></picture>

The images are rendered but the width and height constraints don't work correctly and the images will take the full size of the element they are placed to. Is there a way to exclude the svg images to be processed at all or is there something that could be done to prevent this from happening?

If the processing would keep the width and height properties intact the images would work, such as: <picture><source srcset="/globalassets/svgimage.svg?width=200&height=41&quality=80 200w" width="200" height="41"><img alt="something" src="/globalassets/svgimage.svg?width=200&height=41&quality=80" loading="lazy" decoding="async"></picture>

We are using the latest version of the PictureRenderer: PictureRenderer.Optimizely" Version="3.0.0"

ErikHen commented 11 months ago

Hi. In the last piece of code you meant to have the width + height on the img element, right? That could easily be fixed since there is already support for that in the none-xhtml variant. But I think the best solution is to ignore svg completely. It doesn't make sense to have those in a picture element. It shouldn't be hard to change, I will let you know soon when you can expect a new version.

nguyejon-te commented 11 months ago

Thanks @ErikHen for the swift reply. Looking forward!

ErikHen commented 10 months ago

Please test with version 3.1. The width and height attributes should be carried forward to the img element in the picture element.