Page 1 of 1
png8 and index/alpha transparency
Posted: 2011-02-01T11:13:06-07:00
by Bonzo
I have read Anthony's pages about png8 and transparency and understand that if the image is modified later the transparency will be lost. I asumed that if I just saved the image at the end of manipulation all would be OK but its not.
I have read an artical (
http://blogs.sitepoint.com/2007/09/18/p ... ar-winner/ ) that says I want to use alpha transparency not indexed transparency - is there a way to set this?
This is the command I used:
Code: Select all
exec("convert shed.jpg -resize 200x200 -bordercolor white -border 10x10 temp.png");
exec("convert \( temp.png drawing_pin.png -geometry +180+10 -composite \) -background none -rotate \"-15\" png8:shed_png8.png");
Re: png8 and index/alpha transparency
Posted: 2011-02-01T12:02:47-07:00
by glennrp
"alpha transparency" is PNG or PNG32.
GIF-style transparency (one color is defined to be transparent)
is PNG8 or PNG24 with the tRNS chunk that names a single
transparent color index for PNG8 or a single transparent color for PNG24.
ImageMagick will write an indexed PNG with multiple alpha values
if it can (i.e., when there are 256 or fewer R,G,B,A entries in the
colormap), but it's not a PNG8 if more than one color is
transparent or if any color is semitransparent. Write a PNG32
to prevent that from happening if you don't want it to.
You can exert more detailed control over what the PNG
encoder writes using the "-define PNG:keyword=value"
to set the PNG colortype, bitdepth, and what ancillary chunks
it includes or excludes.
Glenn
Re: png8 and index/alpha transparency
Posted: 2011-02-01T19:35:37-07:00
by anthony
What is happening is that the coder for the normal "PNG" format is being modified to that it can save to a PNG indexed image with multiple transparency when not too many colors are present in the image being saved.
However over the last few releases various bugs have appears that erroneously turns alpha on or off in the saved index PNG image. This is being handled by Glennrp, who is the programmer behind the PNG coder.
As per Glenn's response PNG8 is still a 'GIF' like PNG image. And PNG24 and PNG32 can still be used to override the indexing PNG style that the normal PNG format may attempt to use.
At least this is my understanding of the situation. Glenn can you clarify?
Glenn -- Is there a new 'format' to specifically request indexed PNG? (which like PNG8 may require color reduction)
Re: png8 and index/alpha transparency
Posted: 2011-02-02T13:12:03-07:00
by Bonzo
Thanks for the info; what I want is a png image that renders with variable transparency in new browsers and resorts to the gif type transparency in older browser.
I have found a program that will do what I want - pngquant - the quality is not great in IE6 but it works.
Re: png8 and index/alpha transparency
Posted: 2011-02-02T18:19:28-07:00
by anthony
pngquant is a color reducer (256 color limit) but as a specialized PNG program it creates semi-transparent indexed images correctly. This is what the PNG coder is working on providing.
However you need to remember that IM is a general mutli-format image processor, and can not always specialise in one specific format. It can be beaten by more specialised programs. Things are improving though.
One of my own questions was that now that the coder can do it, how to force IM to generate a indexed PNG with semi-transparency. The answer may solve your problem, especially as things improve.
Re: png8 and index/alpha transparency
Posted: 2011-02-25T13:14:35-07:00
by glennrp
I have revised the PNG encoder to do color reduction when writing a PNG8 instead of
simply rejecting the image when there are more than 256 colors. It's just a simple
truncation algorithm that reduces the image to a 3-3-2 palette. If you want
better, you must reduce the number of colors to 256 (or 255, if the background
color isn't in the palette) prior to calling the PNG decoder.
Similarly, if the image has translucent pixels they are converted to binary
by a simple 50% threshold.
These features are checked into the SVN head (r3729) and should be in IM-6.6.7-10.
Re: png8 and index/alpha transparency
Posted: 2011-02-25T16:14:15-07:00
by anthony
Instead of a 3-3-2 'posterize' palette, could you not just do a -colors 256
By default that generates both transparent and semi-transparnt colors.
EG for PNG8 just do -colors 256
with no other settings or alpha thresholding.
GIF however does some special handling for color reduction as it only wants a single boolean full-transparency color.
Specifically it alpha thresholds, and uses a -quantize transparency setting before color reduction to 255 colors when a transparent color is present after the threshold (256 colors if no transprency).
EG the psuedo code for GIF should be following...
Code: Select all
-channel A -threshold 50%
if (fully-)transparent pixels are present it then...
-quantize transparent -colors 255
otherwise if no transparent pixels present...
-colors 256
Of course -colors should short-circuit if less than the requested number of colors is present.