php - 在 Imagick 的 resizeImage() 函数不起作用的情况下,在大小值数组上使用 foreach() - PHP
问题描述
resizeImage()
我有一张图像,我想使用Imagick中的函数将其重新调整为不同的尺寸。
我在关联数组中设置了一系列宽度,然后用循环遍历它们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, 0, Imagick::FILTER_LANCZOS, 1);
$image->writeImage($destinationFolder . $file);
}
$image->clear();
更新将方法移到$image->clear();
foreach 循环之外后,我不再收到错误消息,但我只得到了一个非常模糊的图像,它是数组中最后一个键的尺寸(1500px 宽)。
解决方案
推荐阅读
- php - 无法在 PHP 中回显 json 数据
- excel - Splitbook,但可以选择使用自定义名称保存 nw 文件工作表
- apache-kafka-connect - 通过 Kafka Connect 转换插入时间戳
- mongodb - 用于在 Macos Mojave 中使用 mongodb-community 版本的 mongod 命令给出错误
- c# - Travis 上的 dotnet 恢复
- azure - 尝试更改 Kubernetes 集群中的最大节点数会返回错误
- android - 面临滑行的 Registry$NoModelLoaderAvailableException 无法从 Firebase 存储中加载图像
- c# - 如何将实体 ID 从 c sharp API 返回到 angular 9?
- java - 直接使用 github 存储库位置的复合构建
- ansible - ansible 模块 postgresql_schema 不支持从数据库中对单个模式进行备份和恢复