Only pass crop parameter when ratio is specified
hirasso opened this issue · comments
Hi @tobimori ,
thanks so much for this beautiful plugin!
Today I suddenly ran into memory issues. While source-diving and playing around, I noticed that in my case, the $file->thumb()
doesn't actually do any downsizing when cropping is set to true
, leading to Memory allocation errors.
kirby-thumbhash/classes/ThumbHash.php
Line 45 in cfc4896
Setting that to false
magically fixed it. While this of course doesn't really make sense and seems to be pointing towards an underlying issue in my Kirby install, I'm still wondering what the reasoning is behind setting cropping to true
?
When you crop an image, you get a FileVersion class, which doesn't support file methods and hence you can't create a thumbhash out of a cropped image.
In order to still support cropped images, you can supply the ratio to the original file method call like so: https://github.com/tobimori/kirby-thumbhash#cropped-images
This is what the plugin uses cropping for.
Whoaa that was quick! 🚀😄
Sorry, I had an error in my original question. I'm asking if crop
should not be set to false
(not true
!) by the plugin.
You could try modifying the line like this and still have ratio/crop support:
'crop' => isset($options['ratio']),
I don't need crop support 😄 I want it off by default
Then just set it to false.
Sure, that's what I did. Do you accept PRs?
Try replacing the script with the following:
https://gist.github.com/tobimori/78eb776ad7fe5e1a608b2d1121fb9d66
Does the error still occur with that?
Yes it's working with the code above!