问题描述
我有一张图片,我想使用 Imagick 中的 resizeImage()
函数将其重新调整为不同的大小。
我在关联数组中设置了一系列宽度,然后使用 foreach()
循环遍历它们。
当我删除 foreach 循环并手动添加特定大小作为宽度参数(例如 150)时,它可以工作,但是当我从带有循环的关联数组中获取值时,它却没有?
// create new class of image from image in memory/tmp_folder
$image = new Imagick($temp);
$sizesjpeg = [
'tiny_' => 50,'small_' => 150,'medium_' => 500,'large_' => 1500,];
$destinationFolder = 'images_lib/';
// image processing of different sizes from the array
foreach ($sizesjpeg as $sizename => $size) {
// setting the height to 0 means it only resizes the width thus keeping the image ratio
$image->resizeImage($size,Imagick::FILTER_lanczos,1);
$image->writeImage($destinationFolder . $file);
}
$image->clear();
UPDATE 将 $image->clear();
方法移到 foreach 循环之外后,我不再收到错误消息,但我只得到了一张非常模糊的图像,它是数组中最后一个键的尺寸(1500 像素宽)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)