【问题标题】:Optimize images to YSlow standards using PHP?使用 PHP 将图像优化为 YSlow 标准?
【发布时间】:2013-05-23 08:27:40
【问题描述】:

我无法找到这个问题的明确答案。

我想无损优化我的图像(主要是 jpg),使其满足 YSlow 的图像优化标准。我无法确定需要采取哪些步骤来执行此操作。

我知道像 smush.it 这样的服务,但我不想依赖 API 或服务。

基本上我正在寻找的是根据 YSlow 的标准优化图像的步骤列表。

仅仅使用GD和改变质量是不够的,我还需要做什么?

【问题讨论】:

    标签: php yslow image-optimization


    【解决方案1】:

    您是否尝试过使用imageinterlace() 生成渐进式 JPG?它使较小的图像略大,但较大的图像要小得多。这是我的图像优化代码的最后一块拼图。

    示例代码

    <?php
    $new_img = imagecreatetruecolor($img_width, $img_height);
    imageinterlace($new_img, true); // Use progressive JPGs
    $white = imagecolorallocate($new_img, 255, 255, 255);
    imagefilledrectangle($new_img, 0, 0, $img_width, $img_height, $white);
    imagecopyresampled($new_img, $img, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
    header("content-type: image/jpg");
    imagejpeg($new_img, NULL, 100);
    imagedestroy($img);
    imagedestroy($new_img);
    die;
    ?>
    

    【讨论】:

      【解决方案2】:

      在 Mike Brittain 的Wesley 项目中实现了与 Smush.it 功能大致相当的功能。它是 Perl 而不是 PHP,但您可以根据需要调整它,或者直接在命令行中使用它。

      它实现了与Smush.it FAQ 中描述的类似的压缩工具和步骤。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-01
        • 2019-12-11
        • 2022-01-12
        • 1970-01-01
        • 2016-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多