Now, I will list some attempts at writing a transparent image as palette PNG. (Only the simplest binary transparency - I didn't even start with partial transparency...)
4) 16bit truecolor+alpha PNG with tRNS chunk warning
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -type PaletteMatte PNG:redblue.png
Magick: tRNS chunk has out-of-range samples for bit_depth `redblue.png' @ warning/png.c/PNGWarningHandler/1457.
IM apparently can't write it as PaletteMatte, so it reverts to full 16bit truecolor+alpha. The picture stays fine.
5) 8bit truecolor+alpha PNG with tRNS chunk warning
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 -type optimize PNG:redblue.png
Magick: tRNS chunk has out-of-range samples for bit_depth `redblue.png' @ warning/png.c/PNGWarningHandler/1457.
Here, it still reverts to 8bit truecolor+alpha - the picture is fine.
6) 2bit palette PNG with tRNS chunk warning
Note: This is the output that I desire - but I want it as palette PNG:
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 PNG:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgba
0,0: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
1,0: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
0,1: ( 0, 0,255,255) #0000FF blue
1,1: ( 0, 0,255,255) #0000FF blue
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 -type PaletteMatte PNG:- | convert - txt:-
Magick: tRNS chunk has out-of-range samples for bit_depth `-' @ warning/png.c/PN
GWarningHandler/1457.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255, 0, 0) #FF0000 red
1,0: (255, 0, 0) #FF0000 red
0,1: ( 0, 0,255) #0000FF blue
1,1: ( 0, 0,255) #0000FF blue
Transparency gets dropped!
In IM v6.6.2-5 it's not successful. But in IM v6.5.8-5, the above command successfully writes a palette PNG with transparency! (But sometimes I seem to get an invalid colormap index error there.)
7) 8bit palette PNG - no transparency and wrong pixel values (without error message)
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 PNG8:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: ( 0, 0,255) #0000FF blue
1,1: (255,255,255) #FFFFFF white
(I can understand the first two white pixels. These probably get replaced with the background color - and the transparency gets lost. But the lower right white pixel?)
8bit palette PNG with tRNS chunk warning - no transparency and wrong pixel values
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 -type PaletteMatte PNG8:- | convert - txt:-
Magick: tRNS chunk has out-of-range samples for bit_depth `-' @ warning/png.c/PNGWarningHandler/1457.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: ( 0, 0,255) #0000FF blue
1,0: ( 0, 0,255) #0000FF blue
0,1: ( 0, 0,255) #0000FF blue
1,1: ( 0, 0,255) #0000FF blue
OK, ok... The transparent pixels are not safe.
(By the way: My older version shows here a 'invalid colormap index error' and fails with 'cannot write image with defined PNG:bit-depth or PNG:color-type'.)
9) BiLevel
In my despair
, I even made some wild tries with '-type BiLevel'. Doesn't make much sense in the above example, but I was interested if I would get an 'ok' image (monochrome of course). But instead I got again random colors!
Perhaps the IM logo gives a better example here:
Code: Select all
convert logo: -monochrome logom.png
This works, but now:
Code: Select all
convert logom.png -type BiLevel logombl.png
??
But back to my normal example:
10) 8bit truecolor PNG - fully opaque and wrong pixel values
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 -define png:color-type=2 PNG:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgba
0,0: (255, 0, 0,255) #FF0000 red
1,0: ( 0,255, 0,255) #00FF00 lime
0,1: ( 0, 0,255,255) #0000FF blue
1,1: (255, 0, 0,255) #FF0000 red
A conversion with color-type 0 or 4 (Grayscale/GrayscaleMatte) gets refused, buth the conversion with type 2 (RGB) was done. OK, so the transparency was not taken, but why again random colors?
EDIT 2: Update for IM v6.6.2-8 or newer
Result is:
# ImageMagick pixel enumeration: 2,2,255,rgba
0,0: (255, 0, 0,
255) #FF0000 red
1,0: (255, 0, 0,
255) #FF0000 red
0,1: ( 0, 0,255,255) #0000FF blue
1,1: ( 0, 0,255,255) #0000FF blue
The colors are ok now. The 'transparency' could still lead to problems though, as the transparent color in the tRNS chunk is always set to black.
Next tries without transparency:
11) attempt at writing with color-type indexed
Code: Select all
convert -size 2x1 xc:red xc:blue -append -depth 8 -define png:color-type=3 PNG:try.png
On my system, ImageMagick crashes.
(By the way: My older IM version shows a "valid palette required for paletted images" error here and creates a corrupt file.)
Update for v6.6.2-9:
creates a 8bit palette PNG - with false colors
Code: Select all
convert -size 2x1 xc:red xc:blue -append -depth 8 -define png:color-type=3 PNG:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255, 0, 0) #FF0000 red
1,0: ( 0, 0,255) #0000FF blue
0,1: ( 0, 0,255) #0000FF blue
1,1: (255, 0, 0) #FF0000 red
Magick: invalid colormap index `R:/Temp/magick-WR6vUc6w' @ error/image.c/SyncImage/3906.
12) 8bit palette PNG with invalid colormap index error
Code: Select all
convert -size 2x1 xc:red xc:blue -append -depth 8 -define png:color-type=3 PNG8:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255, 0, 0) #FF0000 red
1,0: ( 0, 0,255) #0000FF blue
0,1: ( 0, 0,255) #0000FF blue
1,1: (255, 0, 0) #FF0000 red
Magick: invalid colormap index `R:/Temp/magick-qZzn59mR' @ error/image.c/SyncImage/3906.
Next tries again with transparency:
13) 8bit palette PNG - no transparency and wrong pixel values (without error message)
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 -define png:color-type=3 PNG8:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: ( 0, 0,255) #0000FF blue
1,1: (255,255,255) #FFFFFF white
14) 2bit palette PNG with tRNS chunk warning
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 +dither -colors 1000 PNG:- | convert - txt:-
Magick: tRNS chunk has out-of-range samples for bit_depth `-' @ warning/png.c/PNGWarningHandler/1457.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255, 0, 0) #FF0000 red
1,0: (255, 0, 0) #FF0000 red
0,1: ( 0, 0,255) #0000FF blue
1,1: ( 0, 0,255) #0000FF blue
No transparency, but the pixel values are ok.
15) 1bit palette PNG - no transparency and wrong pixel values (without error message)
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 +dither -colors 3 PNG:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: ( 0, 0, 0) #000000 black
1,0: ( 0, 0, 0) #000000 black
0,1: ( 0, 0,255) #0000FF blue
1,1: ( 0, 0,255) #0000FF blue
The background color (bKGD chunk) in this file is black. The transparent pixels are replaced with the background color. Apart from the dropped transparency, I don't understand why the color reduction changes something here. There are only 2 colors in the image. It almost seems that the palette got reduced, not the actual colors. Because up to '-colors 4', the palette contains 4 colors. Now, there are only 2 colors.
16) attempt with color reduction and PNG8 output
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 +dither -colors 3 PNG8:try.png
Magick: invalid colormap index `try.png' @ error/image.c/SyncImage/3906.
Magick: Cannot write image with defined PNG:bit-depth or PNG:color-type. `try.png' @ error/png.c/PNGErrorHandler/1437.
0 byte file. (without transparency in the input, it works)
Update for v6.6.2-9:
creates now a 8bit truecolor+alpha PNG - fully transparent and with false colors:
Code: Select all
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 +dither -colors 3 PNG8:- | convert - txt:-
Magick: invalid colormap index `-' @ error/image.c/SyncImage/3906.
# ImageMagick pixel enumeration: 2,2,255,rgba
0,0: ( 2, 2,203, 0) #0202CB00 rgba(2,2,203,0)
1,0: ( 40, 4,198, 0) #2804C600 rgba(40,4,198,0)
0,1: ( 1, 1,203, 0) #0101CB00 rgba(1,1,203,0)
1,1: ( 40, 4,198, 0) #2804C600 rgba(40,4,198,0)
With another simple image:
17) 8bit palette PNG - no transparency
Code: Select all
convert xc:"rgba(255,255,255,0.0)" xc:"rgba(255,255,255,1.0)" -append -depth 8 PNG8:- | convert - txt:-
# ImageMagick pixel enumeration: 1,2,255,rgb
0,0: (255,255,255) #FFFFFF white
0,1: (255,255,255) #FFFFFF white
It's a bit different here. Could be that ImageMagick only supports binary transparency in PNG8, if all pixels of one color are transparent (or opaque). But my other example - where this was the case - couldn't get written either.
Well, here, apart from dropping the transparency, the image is ok.
18) attempt at writing this image with color reduction and PNG8 output
Code: Select all
convert xc:"rgba(255,255,255,0.0)" xc:"rgba(255,255,255,1.0)" -append -depth 8 -colors 256 PNG8:try.png
Magick: tRNS chunk has out-of-range samples for bit_depth `try.png' @ warning/png.c/PNGWarningHandler/1457.
Magick: invalid colormap index `try.png' @ error/image.c/SyncImage/3906.
Magick: Cannot write image with defined PNG:bit-depth or PNG:color-type. `try.png' @ error/png.c/PNGErrorHandler/1437.
0 byte file.
Update for v6.6.2-9:
Code: Select all
convert xc:"rgba(255,255,255,0.0)" xc:"rgba(255,255,255,1.0)" -append -depth 8 -colors 256 PNG8:- | convert - txt:-
Magick: tRNS chunk has out-of-range samples for bit_depth `-' @ warning/png.c/PN
GWarningHandler/1457.
Magick: invalid colormap index `-' @ error/image.c/SyncImage/3906.
# ImageMagick pixel enumeration: 1,2,255,rgba
0,0: ( 2, 1,198, 0) #0201C600 rgba(2,1,198,0)
0,1: ( 1, 1,198, 0) #0101C600 rgba(1,1,198,0)
So.. Take this image:
convert -size 2x1 xc:red xc:blue -append -transparent red -depth 8 PNG:redblue.png
Is somebody able to write it as palette PNG with the transparency preserved - only with a current ImageMagick?
I couldn't - I only got a lot of errors.
I have also done some other tests with 'normal' palette PNGs (without transparency) and with the background color values.. But I think, this is more than enough now..
Hopefully, someone will be able to make something out of all these messages and images.
Edit 1:
I tried again with the latest IM v6.6.2-7 Q16 (for Windows) - of course, no change.
Edit 2:
Updated cases 10,11,16 and 18 with the results of versions 6.6.2-8 and 6.6.2-9.