Issue
With imagick command, i want to resize image form 2Mb to 200KB, i tried:
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's documentation regarding the resizeImage method require width and height.
How can resize blob image from 2Mb to 200Kb like the command line above.
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
Solution
I have not tested this, but am fairly sure you can use setOption like this to set the upper limit for a JPEG's filesize:
$imagick->setOption('jpeg:extent', $extent);
Answered By - Mark Setchell Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.