[英]How to resize image with imagick php
With imagick command, i want to resize image form 2Mb to 200KB, i tried:使用 imagick 命令,我想将 2Mb 的图像大小调整为 200KB,我试过:
convert a.jpg -strip -define jpeg:extent=200k a1.jpg
And it work.它工作。 But i want to use imagick function of php to resize blob image.
但我想使用 php 的 imagick function 来调整 blob 图像的大小。
Php's documentation regarding the resizeImage method require width and height.关于resizeImage方法的 PHP 文档需要宽度和高度。
How can resize blob image from 2Mb to 200Kb like the command line above.如何像上面的命令行一样将 blob 图像从 2Mb 调整为 200Kb。
I tried:我试过了:
$imageBlob = file_get_contents('a.jpg');
$image = new \Imagick();
$image->readImageBlob($imageBlob);
$height = $image->getImageHeight();
$width = $image->getImageWidth();
$image->resizeImage( $width, $height, \Imagick::FILTER_LANCZOS, 1 );
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_buffer($finfo, $image->getImageBlob());
$mime == "image/svg" && $mime.= "+xml";
$base64 = "data:$mime;base64," . base64_encode($image->getImageBlob());
echo "<img src=\"".$base64.'">';die;
But this doesn't reduce the size from 2Mb to 200Kb但这并没有将大小从 2Mb 减少到 200Kb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.