spacecatninja / craft-imager-x-imagekit-transformer

ImageKit transformer for Imager X
MIT License
0 stars 2 forks source link

Division by zero error when passing a custom profile via the transformerConfig (+suggested fix) #5

Closed jamiepittock closed 6 months ago

jamiepittock commented 6 months ago

I'm currently getting a 'Division by zero' error when passing in a custom profile via the transformerConfig.

{% set transformedImage = craft.imagerx.transformImage(image, { width: width}, {}, {transformerConfig: { profile: imagerProfile }}) %}

I think $profile should be passed as the fourth parameter here when you're creating an instance of ImagekitTransformedImageModel.

https://github.com/spacecatninja/craft-imager-x-imagekit-transformer/blob/03bdbb7a1eae6e2496d768e0085c77ff0935af25/src/transformers/Imagekit.php#L77

This fixes it for me:

return new ImagekitTransformedImageModel($url, $image, $params, $profile); 
aelvan commented 6 months ago

Should be fixed now. Curious where the error was thrown though, I wasn't able to reproduce when quickly testing it.

jamiepittock commented 6 months ago

@aelvan thanks! That's fixed it.

I realised it only happened when the custom profile being used is a web proxy. Sorry, I should have noticed that and mentioned it.

{% set transformedImage = craft.imagerx.transformImage(
    "https://s1.geograph.org.uk/photos/16/80/168021_1f28e99b.jpg", 
    { width: '500' }, 
    {}, 
    { transformerConfig: { profile: 'proxy' } }
) %}

Config...

....
'proxy' => [
    'urlEndpoint' => 'https://ik.imagekit.io/afsdf',
    'isWebProxy' => true
]

Stack trace if it helps... https://pastebin.com/NsjFXeEm