想象getImageLength在裁剪图像后不起作用

问题描述 投票:2回答:2

我想裁剪图像的一部分,然后将部件上传到其他服务器。我必须确保我上传的图片大小低于300k。

$image = new Imagick( $path );
echo $image->getImageLength();

$image->cropImage( $image->getImageWidth(), $image->getImageHeight() / 4, 0, 0 );

echo $image->getImageLength();

第一次使用$ image-> getImageLength()获取图像大小时,返回图像的正确值。但是当我在cropImage之后获得图像大小时它返回0。

处理图像后如何获得正确的值?我想知道它是否小到可以上传。

php image imagick
2个回答
10
投票

最后,我想我找到了裁剪图像后获取文件大小的方法。

使用strlen( $image->getImageBlob() )将始终返回正确的值。


3
投票

似乎Imagick库仅以某种方式计算图像输出后的长度。如果你在之前调用$image->getImageLength()之后调用$image->getImageBlob(),它将返回正确的值。

© www.soinside.com 2019 - 2024. All rights reserved.