spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

Return original value when no image or not safe #244

Closed boboldehampsink closed 10 months ago

boboldehampsink commented 1 year ago

An example of usage is when you don't want to transform SVG images at all. If you keep SVG out of the safe file formats, it won't touch them but still return the original SVG.

aelvan commented 10 months ago

Not sure how I feel about this one though.

In my mind it's more appropriate to signal that the transform could not be done with null, than assuming that the developer want to use the original image if that's the case. At least for the srcset operation, the returned value wouldn't necessarily be a valid value since it wouldn't have the width descriptor?

Couldn't the developer just return the original file url in the gql, and implement whatever logic in the receiving end in regards to what happens if the transform couldn't be done?

Or am I missing something, I often do so please let me know if that's the case. ;)

boboldehampsink commented 10 months ago

@aelvan I understand. Just looking for a solution that works with https://craftcms.com/docs/4.x/config/general.html#transformsvgs - maybe you have a better idea?

aelvan commented 10 months ago

Well, the gist of transformSvgs is covered by safeFileFormats in Imager; if SVG is listed there, it will be transformed, if not, it wont. But, what you're getting at is maybe that asset.getUrl({ width:200 }) in twig, on a svg, with transformSvgs disabled, will return the original assets url?

As I wrote, I'm thinking that it's better to handle this in the application that gets the data. Just returning the original url for the asset together with the transformed url, and then doing a conditional that falls back on the original if it couldn't be transformed.

In addition to feeling a bit iffy, this change would break backwards compatibility for anyone relying on the directives returning null if the file can't be transformed. Which I suspect could be quite disruptive (ie non-image files being used as images).

boboldehampsink commented 10 months ago

Ok thanks, added this in my FE.