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