我使用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图像中的颜色会使文件大小更大
发布评论