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?".
Post Reply
Zmey

Saving PNGs with color type 3 (Palette)

Post by Zmey »

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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Saving PNGs with color type 3 (Palette)

Post by anthony »

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
https://imagemagick.org/Usage/
Zmey

Re: Saving PNGs with color type 3 (Palette)

Post by Zmey »

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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Saving PNGs with color type 3 (Palette)

Post by anthony »

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
https://imagemagick.org/Usage/
Post Reply