哪些转换选项(ImageMagick 或 GraphicsMagick)可生成最小(文件大小)的 PNG?
ImageMagick 创建了一些相当大的 PNG。 GraphicsMagick 好很多,但我仍在寻找与 Convert 一起使用的最佳选项,以获得最小文件大小 png。
我这里有一个 具有小文件大小的大 png,并将其通过 IM 转换传递我一直无法达到该文件大小,更不用说将其变小了。通过 GM 转换,我可以将其变得稍微小一些,但我正在寻求改进,通常适用于我遇到的任何图像。
gm convert -quality 95 a_png.png gm.png
convert -quality 95 -depth 8 a_png.png im.png
gm identify *
a_png.png PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.1K 0.000u 0:01
gm.png[1] PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.0K 0.000u 0:01
im.png[2] PNG 2560x2048+0+0 DirectClass 8-bit 130.2K 0.000u 0:01
哪些选项可以生成最小的 PNG 文件大小?
(是的,我熟悉 OptiPNG、PNGOUT 和 Pngcrush。但我追求的是在我遇到的每个 *nix 盒子上都可以毫无问题地使用的东西待上。)
ImageMagick creates some pretty large PNGs. GraphicsMagick is a lot better, but I'm still looking for the best options to use with convert to obtain the smallest filesize png.
I have here a large png with a small filesize, and passing this through IM convert I have been unable to reach that filesize, let alone get it smaller. With GM convert I can get it slightly smaller but I'm looking for improvements, generically for any image I come across.
gm convert -quality 95 a_png.png gm.png
convert -quality 95 -depth 8 a_png.png im.png
gm identify *
a_png.png PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.1K 0.000u 0:01
gm.png[1] PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.0K 0.000u 0:01
im.png[2] PNG 2560x2048+0+0 DirectClass 8-bit 130.2K 0.000u 0:01
What options for convert produce the smallest PNG filesize?
(Yes, I'm familiar with OptiPNG, PNGOUT and Pngcrush. But I'm after something that will be available without question on every *nix box I happen to be on.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来你和我正在寻找相同的答案。不幸的是,似乎没有多少人对 GraphicsMagick 有很好的了解。这是我到目前为止所了解到的,
质量运算符不适用于 JPEG 以外的任何图像。对我来说,它只是在 PNG 和 GIF 上使用时使文件大小更大。
我已对 PNG 和 GIF 文件执行此操作以减小其大小:
+dither
在颜色减小时停止图像的任何抖动。 (这会减小文件大小)-深度 8
可能是不必要的,因为大多数 PNG 文件已经是深度 8。-colors 50
将图像中的颜色数量减少到 50,这是真正减小以无损格式存储的图像大小的唯一方法如 PNG 或 GIF。显然,为了获得最佳图像质量/尺寸比,您不能在不知道当前深度和颜色数量的情况下仅减少图像深度或颜色数量。 执行以下操作
为了确定此信息,我对我的图像 ;问题
是,当 GraphicsMagick 减少颜色时,它总是减少到至少 255,因此您不能将颜色数量设置为 300。另外 PNG 文件的 alpha 通道似乎也存在问题;如果图像中有透明度,则减少颜色会将这些颜色替换为透明颜色;使用 imagemagick 它不会这样做。
Looks like you and me are looking for the same answer. Unfortunately there doesn't seem to be many people out there with a good knowledge of GraphicsMagick. This is what I have learned so far,
The quality operator doesn't properly work for any image other than JPEG's. For me it just made the file size bigger when used on PNG's and GIF's.
I have done this to my PNG and GIF files to reduce their size:
+dither
stops any dithering of the image when the colors are reduced. (this reduces the file size)-depth 8
is probably unnecessary as most PNG files are already depth 8.-colors 50
reduces the number of colors in the image to 50, this is the only way to really reduce the size of a image stored in a lossless format like PNG or GIF.Obviously for the best image quality/size ratio you cant just reduce the image depth or number of colors without knowing the current depth and number of colors. To determine this information I am doing the following
For my image; this returns
The problem is when GraphicsMagick reduces colors it always reduces to at least 255, so you can't set the number of colors to 300 for example. Also there seems to be an issue with the alpha channel for PNG files; If the image has transparency in it, reducing colors replaces these colors with transparent; with imagemagick it does not do this.
我刚刚再次遇到这个问题,所以我会更新,GraphicsMagick 和 ImageMagick 有一个严重的问题。它们无法使用 tRNS 块写出 PNG 图像,这意味着如果您尝试读入具有 tRNS 块的图像然后将其写出,则该图像会更大。 GM 并不是压缩图像的最佳工具。使用 Image/GraphicsMagick 后,您需要使用单独的工具(例如 OptiPNG)再次压缩 PNG。在图像上运行 GraphicsMagick 后,使用 OptiPNG 时,我得到的文件最多缩小了 60%。
我还想知道您是否遇到过有关 RGBA 图像和位深度的问题。对于某些图像,我收到“无效位深度”异常。我看不出有什么理由。
I just came across this question again so I'll update, GraphicsMagick and ImageMagick have a serious problem. They cannot write out PNG images using a tRNS chunk which means if you try to read in an image that has a tRNS chunk and then write it out, the image will be much bigger. GM is not the best tool for compressing images. You need to use a separate tool such as OptiPNG to compress PNG's again after using Image/GraphicsMagick. I am getting up to 60% smaller files when using OptiPNG after running GraphicsMagick on an image.
Also I was wondering if you have encountered a problem regarding RGBA images and bit depth. For some images I am getting an "Invalid bit depth" exception. I can't see any reason why.
我还没有找到在命令行中执行此操作的方法,但我确实找到了这个免费网站(http://tinypng.org /)效果非常好,我的测试图像缩小了 71%,最终尺寸仅为原始尺寸的 29%。看起来您一次可以给它 20 张图像。我正在研究他们是如何做到的。
http://tinypng.org/
I haven't found a way to do it in the command line, but i did find this free website (http://tinypng.org/) that does an excellent job, my test image got a 71% reduction, final size was only 29% of the original. It looks like you can give it 20 images at a time. I'm looking into how they do it.
http://tinypng.org/