I made a small code for resizing images present on my server. I am testing it on xampp. Here it is:
if ($img_width[0] >= 750) { $imagick_image_width = 920; }
elseif (($img_width[0] > 500) && ($img_width[0] < 750)) { $imagick_image_width = 500; }
elseif (($img_width[0] >= 200) && ($img_width[0] <= 500)) { $imagick_image_width = 500; }
$save_path = 'c:/xampp/htdocs/images/'.$image_name.'.jpg';
$image = new Imagick($save_path);
$image->resizeImage($imagick_image_width, 0,Imagick::FILTER_LANCZOS,0.95); //line 226
$image->writeImage($save_path);
$image->destroy();
I have taken img_width via getimagesize array.
When executed this gives error:
Fatal error: Uncaught exception 'ImagickException' with message 'Invalid image geometry' in C:\xampp\htdocs\test-templ.php on line 226
ImagickException: Invalid image geometry in C:\xampp\htdocs\test-templ.php on line 226
How to resolve this?
The bestfit parameter is poorly documented. You need to set it to false if you set one of the dimensions to 0.
If bestfit=false and height=0 then a proportional height will be calculated by imagemagick. If bestfit=true and height=0 you will get the "Invalid image geometry" error.
bestfit=true should only be used when both width and height are specified, and it will adjust one dimension to keep the aspect ratio consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With