开发者

How to save 8-bit PNGs with ChunkyPNG or RMagick

I've been trying to save 8-bit PNGs (PNG8) using RMagick (http://rmagick.rubyforge.org/) and ChunkyPNG (https://github.com/wvanbergen/chunky_png) but have been unable to do so.

However the only time I can get it to work on RMagick is if the ImageMagick installation is based on the QuantumDepth of 8 rather than the usual 16. It is not possible to change this settin开发者_开发技巧g on the fly - the installation of ImageMagick has to be compiled with this setting. Also setting the depth to 8 when creating the image or prefixing a format type when saving have no effect.

ie. img.write('PNG8:image.png')

Anyway I've had a look at ChunkyPNG and I really prefer to use this over RMagick - simply because it is pure Ruby and doesnt depend on ImageMagick. I can't save a PNG8 using that too.

I have to convert the PNG to 8bit afterwards using a graphics program -

My questions:

  1. Is there a way of saving 8bit PNGs properly like it does on ImageMagick Q8 on a machine with ImageMagick Q16 installed?

  2. Can anyone provide pointers as to do my own 4-bit encoder in ChunkyPNG or know of a way to save PNG8 with it?

Thanks in advance..


What exactly do you mean by PNG8? 8-bit grayscale, 8-bit indexed color, 3x8 bit RGB or 4x8 bit RGBA? All of these color modes are supported by ChunkyPNG.

By default, ChunkyPNG tries to determine the best color mode to save your image. You can overwrite it by providing an options hash to the save method:

image.save('filename.png', color_mode: ChunkyPNG::COLOR_TRUECOLOR)
# Or: ChunkyPNG::COLOR_TRUECOLOR_ALPHA    

image.to_blob(color_mode: ChunkyPNG::COLOR_INDEXED, bit_depth: 8)

More info: https://github.com/wvanbergen/chunky_png/wiki

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜