使用 Imagick 和 Gmagick 调整大小后的图像文件大小

发布于 2024-12-13 01:10:33 字数 399 浏览 7 评论 0原文

在调整图像大小时,我注意到 Imagick 和 Gmagick 使用相同的选项在 HDD 上生成具有不同文件大小的图像:

$image = new Imagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_imagick.jpg");

输出 88kb 的图像

$image = new Gmagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_gmagick.jpg");

输出 15kb 的图像

有人知道为什么差异如此之大吗?

While resizing an image, I have noticed that Imagick and Gmagick produce images with different filesize on HDD with the same options:

$image = new Imagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_imagick.jpg");

outputs an Image with 88kb

$image = new Gmagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_gmagick.jpg");

outputs an Image with 15kb

Does someone have any idea, why the difference is so huge?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2024-12-20 01:10:33

尝试在调整大小之前设置图像压缩设置。

     $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(80);

此外,检查生成图像的大小。 PHP 文档中的注释让我相信,thumbnailImage 的自动调整部分并不像您在 IMagick 中所期望的那样工作。

来自 PHP 文档:

thumbnailImage 的拟合功能并不像人们预期的那样工作。相反,使用 >this 制作最大尺寸为 200x82 的缩略图:

 // 创建最大尺寸为 200x82 的缩略图
    $width=$im->getImageWidth();
    if ($width > 200) { $im->thumbnailImage(200,null,0); } }

    $height=$im->getImageHeight();
    if ($height > 82) { $im->thumbnailImage(null,82,0); } }

Try setting the image compression settings prior to resizing.

     $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(80);

Additionally, check the size of the resulting image. Comments in the PHP documentation lead me to believe that the automatic fit portion of thumbnailImage does not work as you would expect in IMagick.

From PHP Docs:

The fit functionality of thumbnailImage doesn't work as one would anticipate. Instead, use >this to make a thumbnail that has max of 200x82:

    // Create thumbnail max of 200x82
    $width=$im->getImageWidth();
    if ($width > 200) { $im->thumbnailImage(200,null,0); }

    $height=$im->getImageHeight();
    if ($height > 82) { $im->thumbnailImage(null,82,0); }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文