mmikkel / Retcon-Craft

A collection of powerful Twig filters for modifying HTML
MIT License
79 stars 9 forks source link

Transform fails if image is svg #38

Closed espensgr closed 1 year ago

espensgr commented 2 years ago

We are using the retconSrcset on a redactor field, that can add images. If you add an svg it fails as imager-x cant do that. Is it possible to skip svg files in the selector for retconSrcset? Or is this an imager-x setting, or bug?

mmikkel commented 2 years ago

The thing is that (AFAIK) Imager can transform SVGs, it depends on the transformer its using. In most cases though, I guess it isn't able to (and you wouldn't want it to), so as a default behaviour it'd probably make sense if Retcon didn't attempt to transform SVGs at all.

I'll have a think on how to approach that – but in the meantime, a quick workaround is to use the Retcon selector to avoid transforming any SVG files, i.e. something like this (note the 'img:not([src$=".svg"])'):

{{ entry.redactorField|retconSrcset(
    [
        {width: 375},
        {width: 480},
        {width: 768}
    ],
    'img:not([src$=".svg"])',
    '(min-width: 40em) 80vw, 100vw'
) }}
espensgr commented 2 years ago

that makes sense, thanks for the solution, will implement it 👍

mmikkel commented 1 year ago

Circling back to this, I think I found a decent solution.

From the next release forward, Retcon will respect Imager's safeFileFormats setting (defaults to ['jpg', 'jpeg', 'gif', 'png'] when using Imager to transform images. I.e. the retconTransform and retconSrcset filters will no longer attempt to transform SVGs or other non-safe formats, unless those formats have been added to the safeFileFormats setting in Imager's config file.

anita-chouhan commented 1 year ago

Hi, we have a project with Imager and Retcon plugins. We recently upgraded the Retcon plugin to the version 2.7.0 and found that it's giving errors on image transforms:

Screenshot 2023-10-27 at 5 03 05 PM

Additional info

mmikkel commented 1 year ago

@anita-chouhan Responded in a new issue: https://github.com/mmikkel/Retcon-Craft/issues/66