我想用ImageMagick压缩一个JPG图像文件,但在大小上没有太大的差别。默认情况下,输出大小大于输入大小。我不知道为什么,但在添加了一些+配置文件选项并设置了质量后,我可以得到一个较小的尺寸,但仍然与原始的相似。
输入图像大小为255kb,处理后图像大小为264kb (使用+profile去除配置文件,质量设置为70%)。有没有办法将图像压缩到至少150kb?这有可能吗?我可以使用哪些ImageMagick选项?
发布于 2017-05-27 03:09:36
我使用的是Google Pagespeed Insights镜像优化指南,对于ImageMagick,他们推荐以下内容:
-采样因子4:2:0
-strip
-quality 85 [it can vary, I use range 60-80, lower number here means smaller file]
-interlace
-colorspace RGB
ImageMagick中的命令:
convert image.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB image_converted.jpg
使用这些选项,我可以节省高达40%的JPEG大小,而不会有太多明显的损失。
发布于 2014-11-26 14:03:02
对于那些在PHP中使用Imagick类的人来说:
$im -> gaussianBlurImage(0.8, 10); //blur
$im -> setImageCompressionQuality(85); //set compress quality to 85
发布于 2018-03-08 21:30:42
对于那些在PHP中使用Imagick的用户,这里有一个完整的解决方案:
$im = new \Imagick($filePath);
$im->setImageCompression(\Imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(85);
$im->stripImage();
$im->setInterlaceScheme(\Imagick::INTERLACE_PLANE);
// Try between 0 or 5 radius. If you find radius of 5
// produces too blurry pictures decrease to 0 until you
// find a good balance between size and quality.
$im->gaussianBlurImage(0.05, 5);
// Include this part if you also want to specify a maximum size for the images
$size = $im->getImageGeometry();
$maxWidth = 1920;
$maxHeight = 1080;
// ----------
// | |
// ----------
if($size['width'] >= $size['height']){
if($size['width'] > $maxWidth){
$im->resizeImage($maxWidth, 0, \Imagick::FILTER_LANCZOS, 1);
}
}
// ------
// | |
// | |
// | |
// | |
// ------
else{
if($size['height'] > $maxHeight){
$im->resizeImage(0, $maxHeight, \Imagick::FILTER_LANCZOS, 1);
}
}
https://stackoverflow.com/questions/7261855
复制相似问题