2

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?

4

1 回答 1

0

$imagick_image_width在使用它来调整大小之前检查变量的值。我遇到了同样的错误,参考它我的 laravel 代码无法从“env”文件中读取值。

尝试$imagick_image_width使用任何默认大小初始化变量。

于 2021-12-11T09:16:44.100 回答