Hi, I have some png files, they dont have many colors in them so they are candidates for file size reduction by converting to palette PNGs. I.e. can ImageMagick read in a PNG, quantise it by analysing it to work out the best set of 16 colors (RGB and alpha) to represent it and then saving it as a 4-bit PNG. On the Windows command line. Can ImageMagick do this conversion? If not, can it convert to 256 colors (8 bit). Note there are semi-transparent pixels involved.
In the manual it says it that it doesn't deal with semi-transparent pixels, not sure if this is just the default.
Quantise png preserving semi transparency
-
- Posts: 16
- Joined: 2012-11-15T06:43:37-07:00
- Authentication code: 6789
Re: Quantise png preserving semi transparency
ImageMagick-6.8.0-5 will write a paletted PNG by default if the input image has 256 or fewer RGBA colors (including
the background color), even if some of them are semitransparent. Just run "convert input.png output.png". To reduce
the color count to 16 use "convert input.png -colors 16 output.png". To get the bit-depth down to 4 you might need to
use "-colors 15" instead of "-colors 16" to leave room for the background color in the palette.
What is the manual reference that you mentioned?
the background color), even if some of them are semitransparent. Just run "convert input.png output.png". To reduce
the color count to 16 use "convert input.png -colors 16 output.png". To get the bit-depth down to 4 you might need to
use "-colors 15" instead of "-colors 16" to leave room for the background color in the palette.
What is the manual reference that you mentioned?
-
- Posts: 16
- Joined: 2012-11-15T06:43:37-07:00
- Authentication code: 6789
Re: Quantise png preserving semi transparency
Thanks glenrp, that worked perfectly.
FYI, the bit in the manual I was referring to ...
http://www.imagemagick.org/Usage/formats/#png_formats
it says: "PNG8 was defined by PhotoShop, not the PNG group. And while it can handle multiple semi-transparent colors, as well as a fully-transparent color, IM assumes that it doesn't"
And when I tried the suggested command: "convert {input_image} -type Palette indexed.png",
it indeed removed all partially transparent pixels
Maybe I didnt read enough, but at this point I assumed ImageMagick could not handle partial transparency and so nearly gave up on it.
FYI, the bit in the manual I was referring to ...
http://www.imagemagick.org/Usage/formats/#png_formats
it says: "PNG8 was defined by PhotoShop, not the PNG group. And while it can handle multiple semi-transparent colors, as well as a fully-transparent color, IM assumes that it doesn't"
And when I tried the suggested command: "convert {input_image} -type Palette indexed.png",
it indeed removed all partially transparent pixels
Maybe I didnt read enough, but at this point I assumed ImageMagick could not handle partial transparency and so nearly gave up on it.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Quantise png preserving semi transparency
to retain binary transparency, tryAnd when I tried the suggested command: "convert {input_image} -type Palette indexed.png",
convert {input_image} -type Palettematte indexed.png
or
convert {input_image} PNG8:indexed.png
or
convert {input_image} -type Palettematte PNG8:indexed.png
If those don't work, the Glenn would likely have the commands to use from http://www.imagemagick.org/Usage/formats/#png_write