给定用户上传的图像,我需要创建它的各种缩略图以在网站上显示。我正在使用 ImageMagick 并试图让 Google PageSpeed 满意。不幸的是,无论如何quality
我在 convert
中指定的值命令,PageSpeed 仍然能够建议进一步压缩图像。
请注意 http://www.imagemagick.org/script/command-line-options.php?ImageMagick=2khj9jcl1gd12mmiu4lbo9p365#quality提到:
For the JPEG ... image formats, quality is 1 [provides the] lowest image quality and highest compression ....
实际上,我什至测试了使用 1 压缩图像(尽管它产生了一个无法使用的图像)并且 PageSpeed 仍然建议我仍然可以通过“无损压缩”图像来优化这样的图像。我不知道如何使用 ImageMagick 压缩图像了。 有什么建议?
这是测试我所谈论内容的快速方法:
assert_options(ASSERT_BAIL, TRUE);
// TODO: specify valid image here
$input_filename = 'Dock.jpg';
assert(file_exists($input_filename));
$qualities = array('100', '75', '50', '25', '1');
$geometries = array('100x100', '250x250', '400x400');
foreach($qualities as $quality)
{
echo("<h1>$quality</h1>");
foreach ($geometries as $geometry)
{
$output_filename = "$geometry-$quality.jpg";
$command = "convert -units PixelsPerInch -density 72x72 -quality $quality -resize $geometry $input_filename $output_filename";
$output = array();
$return = 0;
exec($command, $output, $return);
echo('<img src="' . $output_filename . '" />');
assert(file_exists($output_filename));
assert($output === array());
assert($return === 0);
}
echo ('<br/>');
}
最佳答案
您可以运行 jpegtran或 jpegoptim在您创建的文件上,进一步减小它的大小。
关于image-processing - Google PageSpeed 和 ImageMagick JPG 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3899898/