imagemagick 调整大小和质量 PNG

发布于 2024-12-11 21:56:19 字数 251 浏览 6 评论 0原文

在我的应用程序中,我需要调整 PNG 文件的大小并降低其质量。

全尺寸的 PNG 为 3100x4400 像素,使用 2.20MB 磁盘空间。

运行以下命令时:

convert -resize 1400 -quality 10 input.png output.png

使用 5,33MB 磁盘空间将图像大小调整为 1400x2000。

所以我的问题是:如何减小文件大小?

In my application I need to resize and make the quality on PNG files poorer.

In full size the PNGs are 3100x4400px using 2,20MB disk space.

When running the following command:

convert -resize 1400 -quality 10 input.png output.png

the images are resized to 1400x2000 using 5,33MB disk space.

So my question is: How can I reduce the file size?

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

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

发布评论

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

评论(5

怕倦 2024-12-18 21:56:19
  1. 您可以通过使用色调分离进一步降低 PNG 的质量:

    https://github.com/pornel/mediancut-posterizer (Mac GUI)

    这是一个有损操作,可以让 zlib 更好地压缩。

  2. 使用 pngquant 将图像转换为 PNG8。

    它将图像减少到 256 色,因此质量取决于图像的类型,但 pngquant 提供了非常好的调色板,因此您可能会惊讶于它的工作频率。

  3. 使用Zopfli-pngAdvPNG 可以更好地重新压缩图像。

    这是无损的,如果您有空闲的 CPU 周期,建议对所有图像使用此方法。

  1. You can further reduce quality of PNG by using posterization:

    https://github.com/pornel/mediancut-posterizer (Mac GUI)

    This is a lossy operation that allows zlib to compress better.

  2. Convert image to PNG8 using pngquant.

    It reduces images to 256 colors, so quality depends on the type of image, but pngquant makes very good palettes, so you might be surprised how often it works.

  3. Use Zopfli-png or AdvPNG to re-compress images better.

    This is lossless and recommended for all images if you have CPU cycles to spare.

岁月无声 2024-12-18 21:56:19

使用imagemagick调整大小后,可以使用pngquant

在 mac 上(使用自制软件)brew install pngquant 然后:

pngquant <filename.png>

这将创建一个新图像 filename-fs8.png,其尺寸通常要小得多。

After using imagemagick to resize, you can compress the image using pngquant.

On mac (with homebrew) brew install pngquant then:

pngquant <filename.png>

This will create a new image filename-fs8.png that is normally much smaller in size.

童话里做英雄 2024-12-18 21:56:19

对于那些懒惰的人来说,想要粘贴到一个衬垫中:

mogrify -resize 50% -quality 50 *.png && pngquant *.png --ext .png --force 

这会修改当前目录中的所有 png,因此请确保您有备份。根据您的需要修改调整大小和质量参数。我做了一个快速实验,首先是 mogrify,然后是 pngquant,结果图像尺寸明显更小。

pngquant 的 ubuntu 软件包称为“pngquant”,但我已经将它安装在 20.04LTS 上,所以看起来它可能默认存在。

For lazy people that arrived here wanting to paste in a one liner:

mogrify -resize 50% -quality 50 *.png && pngquant *.png --ext .png --force 

This modifies all of the pngs in the current directory in place, so make sure you have a backup. Modify your resize and quality parameters as suits your needs. I did a quick experiment and mogrify first, then pngquant, resulted in significantly smaller image size.

The ubuntu package for pngquant is called "pngquant" but I had it installed already on 20.04LTS so seems like it may be there by default.

心如狂蝶 2024-12-18 21:56:19

帮助页面显示,与 PNG 一起使用的 -quality 选项设置了 zlib 的压缩级别,其中(大致)0 是最差的压缩,100 - 是最好的(默认为 75)。因此,请尝试将 -quality 设置为 100,甚至删除该选项。

另一种方法是指定 PNG:compression-level=NPNG:compression-strategy=NPNG:compression-filter=N取得更好的成果。

http://www.imagemagick.org/script/command-line-options .php#质量

Help page says, that -quality option used with PNG sets the compression level for zlib, where (roughly) 0 is the worst compression, 100 - is the best (default is 75). So try to set -quality to 100 or even remove the option.

Another method is to specify PNG:compression-level=N, PNG:compression-strategy=N and PNG:compression-filter=N to achieve even better results.

http://www.imagemagick.org/script/command-line-options.php#quality

秋意浓 2024-12-18 21:56:19

我发现最好的方法是使用

- density [value] 

参数。

I found that the best way was to use the

- density [value] 

parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文