如何在命令行中缩小、缩放和减少 PNG 的颜色? (Linux,生成文件)
我喜欢在 Makefile 中减小 PNG 的大小。
我首先尝试了 ImageMagick,但是虽然我可以调整(缩小)图像大小并将其颜色减少到 32(或深度减少到 5 位),但在大多数情况下实际文件大小比原始文件大小更大。
使用 GraphicsMagick 的结果相似,有时稍好,有时更差。
[gm] 转换 input.png -trim -resize 600 -深度 5 -quality 100 输出.png
使用 Gimp,结果总是完美的。将图像缩小并将颜色减少到 32 种后,生成的图像始终比原始图像小得多。不幸的是,从 Makefile 使用 Gimp 有点困难,而且我不懂 lisp,只懂 Python。
问题: - 有没有办法让 ImageMagick 或 GraphicsMagick 减小 PNG 大小? - 是否有一种简单的方法可以使用 Gimp 来执行此转换,最好使用 Python? - 有其他免费工具可以帮助完成这项任务吗?
From within a Makefile I like to reduce the size of PNGs.
I tried first ImageMagick, but while I could resize (down) the images and reduce their colours to 32 (or the depth to 5 bits), the actual file size was bigger than the original in most cases.
With GraphicsMagick the results are similar, sometimes slightly better, sometimes worse.
[gm] convert input.png -trim -resize 600 -depth 5 -quality 100 output.png
With the Gimp, the results are always perfect. After down-scaling the image and reducing the colours to 32, the resulting images are always much smaller than the originals. Unfortunately, using the Gimp from a Makefile is a little bit difficult and I don't know lisp, only Python.
Questions:
- Is there a way to make ImageMagick or GraphicsMagick reduce the PNG size?
- Is there an easy way of performing this transformations with the Gimp instead, preferable using Python?
- Are there other free tools around to help with this task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我回答我自己的问题。在
Makefile
中,必须创建并使用临时 Gimp 目录,以便使用版本控制系统中的脚本,而不是任意本地副本。应该批量处理图像文件,因为Gimp启动速度比较慢。脚本
downsize.py
是一个普通的 Gimp Python 脚本,主要包含以下内容:这段代码可能不正确,这只是基本思想。
I answer my own question. In the
Makefile
one has to create and use a temporary Gimp directory, so that one uses the script from the version control system, not an arbitrary local copy. One should batch process image files, because Gimp is relatively slow in startup.The script
downsize.py
is a normal Gimp Python script, which mainly contains something like:This code may not be correct, it's just the basic idea.
尝试 pngcrush: http://pmt.sourceforge.net/pngcrush/
Try pngcrush: http://pmt.sourceforge.net/pngcrush/