gpt4 book ai didi

image-processing - Google PageSpeed 和 ImageMagick JPG 压缩

转载 作者:行者123 更新时间:2023-12-03 22:29:17 25 4
gpt4 key购买 nike

给定用户上传的图像,我需要创建它的各种缩略图以在网站上显示。我正在使用 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/>');
}

最佳答案

  • JPEG 可能包含可以删除的注释、缩略图或元数据。
  • 有时可以更多地压缩 JPEG 文件,同时保持相同的质量。如果生成图像的程序没有使用最佳算法或参数来压缩图像,这是可能的。通过重新压缩相同的数据,优化器可以减小图像大小。这通过使用 specific Huffman tables 起作用用于压缩。

  • 您可以运行 jpegtranjpegoptim在您创建的文件上,进一步减小它的大小。

    关于image-processing - Google PageSpeed 和 ImageMagick JPG 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3899898/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com