减少PNG图像中的颜色会使文件大小更大

编程入门 行业动态 更新时间:2024-10-27 04:25:00
本文介绍了减少PNG图像中的颜色会使文件大小更大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用ImageMagick通过减少图像中的颜色以编程方式减小PNG图像的大小。我得到的图像unique-colors并除以2.然后我将这个值分配给-colors选项如下:

variable = unique-colors / 2

convert image.png -colors变量-depth 8

我认为这会大大减少图片的大小,而是增加磁盘上的图像大小。

感谢。

编辑:结果是问题是抖动。抖动帮助您减少的彩色图像看起来更像原件,但增加了图像大小。要删除ImageMagick中的抖动,请将+添加到您的命令。 示例

convert CandyBar.png + dither-colors 300 -depth 8 smallerCandyBar.png

解决方案

Imagemagick可能使用一些抖动算法,使图像看起来好像它有原始的颜色。这增加了图像数据随机性(单个像素在某些地方被重新混合以融合成其他颜色),并且该图像数据不再被打包。进一步研究如何转换命令执行抖动。您还可以通过在gimp /等效程序中添加第二个图像作为图层并调整透明度来查看此效果。

I am using ImageMagick to programmatically reduce the size of a PNG image by reducing the colors in the image. I get the images unique-colors and divide this by 2. Then I assign this value to the -colors option as follows:

variable = unique-colors / 2

convert image.png -colors variable -depth 8

I thought this would substantially reduce the size of the image but instead it increases the images size on disk. Can anyone shed any light on this.

Thanks.

EDIT: Turns out the problem was dithering. Dithering helps your reduced color images look more like the originals but adds to the image size. To remove dithering in ImageMagick add +dither to your command. Example

convert CandyBar.png +dither -colors 300 -depth 8 smallerCandyBar.png

解决方案

Imagemagick probably uses some dithering algorithm to make image appear as though it has original amount of colors. This increases image data "randomness" (single pixels are recolored at some places to blend into other colors) and this image data no longer packs as well. Research further into how the convert command does the dithering. You can also see this effect by adding second image as a layer in gimp/equivalent program and tuning transparency.

更多推荐

减少PNG图像中的颜色会使文件大小更大

本文发布于:2023-06-09 06:29:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/596866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件大小   更大   会使   图像   颜色

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!