aelvan / Imager-Craft

This plugin has been DEPRECATED. Check out Imager X instead.
MIT License
342 stars 69 forks source link

Sending incorrect ratio parameters to imigx #292

Closed iainhenderson closed 4 years ago

iainhenderson commented 4 years ago

I think there may be a problem in how Imager constructs parameters for imigix.

I'm using this twig code to generate a srscet for a picture element

{% set imageTransforms = craft.imager.transformImage(image, [
        { width: 120},
        { width: 1920}
], {ratio: '3/4', position: '50% 50%'}, {fillTransforms: true, fillInterval: 120 }) %}

This produces URLs like:

https://preventionhub.imgix.net/assets/src/uploads/SH_0409.jpg?auto=compress%2Cformat&fit=clip&ixlib=php-1.1.0&position=50%2050&q=50&ratio=3%2F4&w=240

URL decoded the parameter string is: "?auto=compress,format&fit=clip&ixlib=php-1.1.0&position=50 50&q=50&ratio=3/4&w=240"

However looking at Imigix API documentation the ratio parameter should be formatted "ar=3:4" not "ratio="3/4" See: https://docs.imgix.com/apis/url/size/ar

Additionally the ratio parameter only takes effect when the 'fit' parameter is set to 'crop' and doesn't work with 'clip'. I'm assuming 'fit=clip' may be being sent as a height and width are not specified for the transform. I can fix that my manually specifying the clip mode, but perhaps it should use crop if a ratio is defined.

aelvan commented 4 years ago

The ratio parameter should be a number, not a string, ie ratio: 3/4. Then it'll work as expected.

iainhenderson commented 4 years ago

Ahh, I can see it's now passing a height parameter through instead of ratio. Thanks for clearing that up for me @aelvan