3

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?

g13
  • 139
  • 4
  • 11
  • 1
    You're passing 0 for height parameter, that's probably why imagick is complaining. – krcko Apr 22 '13 at 09:30
  • 2
    2.1.0 Added optional fit parameter. This method now supports proportional scaling. Pass zero as either parameter for proportional scaling. http://php.net/manual/en/imagick.resizeimage.php – g13 Apr 22 '13 at 09:32
  • I've forgotten about that, sorry. But on second read I've noticed that you are setting $imagick_image_width, but you are using $size_imagick_image variable. Is it a typo or is there some more code? – krcko Apr 22 '13 at 09:37
  • Oops, that was a typo, I edited the code. – g13 Apr 22 '13 at 10:21
  • What's the value of $img_width? – krcko Apr 22 '13 at 10:40
  • If it is an integer why are you using it as an array (`$img_width[0]`) then? – krcko Apr 22 '13 at 10:50
  • $img_width is the value returned by function getimagesize. It saves that value at 0 position in array. For reference : http://stackoverflow.com/questions/11607152/is-that-possible-to-find-width-and-height-of-an-image-using-php-dom – g13 Apr 22 '13 at 10:53
  • I know what getimagesize returns but since there was no call to getimagesize in code your posted code I had to ask. – krcko Apr 22 '13 at 10:58
  • I haven't added that part! – g13 Apr 22 '13 at 11:03
  • Have you solved your problem? I have it too. – T3rm1 Oct 18 '17 at 14:03

1 Answers1

0

Check value of $imagick_image_width variable before using it for resizing. I was getting the same error, and with reference to it my laravel code was unable to read values from 'env' file.

Try Initializing the $imagick_image_width variable with any default size.

Elikill58
  • 4,050
  • 24
  • 23
  • 45