Saving PNGs with color type 3 (Palette)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".

Saving PNGs with color type 3 (Palette)

Postby Zmey » 2008-05-29T02:53:25+00:00

I'm trying to save PNG with color type 3 using ImageMagick:

Source image has color type 3 (PALETTE).
> convert image.png image_out.png
Image_out.png has color type 6 (RGBA).
> convert -type Palette image.png image_out.png
Image_out.png has color type 2 (RGB).

Currently I'm saving to GIF as workaround:
convert image.png image_out.gif
pngout /kp image_out.gif image_out.png
Image_out.png has color type 3 (PALETTE).

But this has a side effect: resulting palette is larger than needed (GIF palette size are 256, 128, 64 etc colors, unused colors are filled with zeros). I can't let pngout remap palette colors (/kp switch disables this) and drop unused ones because I use the same palette for different images.

Is there a way to save palettized PNG directly from ImageMagick?
Zmey
 

Re: Saving PNGs with color type 3 (Palette)

Postby anthony » 2008-06-04T23:18:24+00:00

use png8:image.png png8 makes the png image output act like it was GIF, with all the limitations of GIF.

For better methods you may like to look at pngnq instead
See http://imagemagick.org/Usage/formats/#png_non-im
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Saving PNGs with color type 3 (Palette)

Postby Zmey » 2008-06-07T06:31:36+00:00

anthony wrote:use png8:image.png png8 makes the png image output act like it was GIF, with all the limitations of GIF.

For better methods you may like to look at pngnq instead
See http://imagemagick.org/Usage/formats/#png_non-im


Adding png8: before filename helped. Thanks!

At http://imagemagick.org/Usage/formats/#png_non-im there's following text:
Code: Select all
If when reading an image you force IM to create a image color index table
(or palette) then IM will save that image using a "png8:" format...

    convert input.jpg  -type Palette  output.png

This no longer works with latest versions of ImageMagick...
It saves image in png8 format only if "png8:" is specified explicitly.
Zmey
 

Re: Saving PNGs with color type 3 (Palette)

Postby anthony » 2008-06-09T18:19:14+00:00

It is most likely that the PNG coder does not understand the generation of a palette style PNG. PNG8 is designed for that but only with the GIF image limitations.

Even though PNG8 could allow the use of multiple semi-transparent colors in a very specific arrangement in the palette. the IM png8 coder does not know how to output such an image.

You are of course welcome to extend the coder to allow this, as IM's color quantization is probably better than the PNG ones. Has anyone done a comparision, and like to repoort the results?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia


Return to Users

Who is online

Users browsing this forum: Bing [Bot] and 22 guests