Page 1 of 1
transparent-color setting
Posted: 2009-01-15T13:01:40-07:00
by rs13
Hello,
I have a pressing problem that I have been tackling for days but unsuccessfully. I wonder if you guys can help me. I am creating a png image which I want to make sure has transparent background. Everything works well until I try to view that image in IE 6. In IE 6, the image shows pure black background instead of transparent background -- I know this is a well known IE 6 bug.
From what I understand, the png image by default has a transparent color set to black and if the browser or anything else cannot correctly render the transparency, it shows up black.
To solve that, I have update my ImageMagick to the latest version and ran:
convert 2_offwhite.png -fill "#0000ff" -opaque "#fffffe" -transparent-color white 2_offtrans.png
I understood that this '-transparent-color' option will allow me to reset the transparent color to white instead of black. However, it seems that IE 6 still renders the image with black background even after I execute this command.
I would sincerely appreciate any help you can give me as I really need to be able to control and set the transparency color to white so it shows up white in anything that cannot render the transparency correctly.
With Regards,
Robert
Re: transparent-color setting
Posted: 2009-01-15T20:19:57-07:00
by anthony
Window Internet Exporer v6 is brain dead with regard to PNG and transparency. It was fixed for IE v7 though.
Typically websites add a little java script to allow IE6 to handle such images correctly (well good enough for typical usage).
See My notes on this problem (whcih I used for IM Examples) in
http://www.imagemagick.org/Usage/formats/#png_www
Re: transparent-color setting
Posted: 2009-01-20T14:45:18-07:00
by rs13
Hello Anthony,
Thank you for your prompt answer. I have dug deeper into different commands that can help me deal with transparency color and inconsistencies that exists in different renderers (not limited to web browsers). Through this effort however, I started to question the reliability of the convert command all together as I found that running as something trivial as:
exec('convert -strip -density 300x300 -units PixelsPerInch ' .
"../..".$_GET['dir'] . ' -fill "#fffffe" -opaque "#ffffff" -background white -fill "#ffffff" -opaque none ' .
"../..".$_GET['dir']);
does not even correctly convert anything that is #ffffff to #fffffe. It seems as if it does do so but not 100%. I still find in the resulting image spots of #ffffff. This leaves me puzzled as I cannot really rely on the '-fill' command to do any image alterations.
Can you please shed some light on this as I am at loss and I must be missing something?
With Regards,
Robert
Re: transparent-color setting
Posted: 2009-01-20T18:07:36-07:00
by anthony
rs13 wrote:HThrough this effort however, I started to question the reliability of the convert command all together as I found that running as something trivial as:
exec('convert -strip -density 300x300 -units PixelsPerInch ' .
"../..".$_GET['dir'] . ' -fill "#fffffe" -opaque "#ffffff" -background white -fill "#ffffff" -opaque none ' .
"../..".$_GET['dir']);
does not even correctly convert anything that is #ffffff to #fffffe. It seems as if it does do so but not 100%. I still find in the resulting image spots of #ffffff. This leaves me puzzled as I cannot really rely on the '-fill' command to do any image alterations.
Can you please shed some light on this as I am at loss and I must be missing something?
The problem is that -opaque is an exact command. If the color is NOT exactly that color specified, it is not changed. This is especially bad for JPEG which does not produce exact colors!
Try adding a little
-fuzz, say 2%, to the image to make 'near colors' also match.
See
http://www.imagemagick.org/Usage/color/#fuzz
I myself dislike using -opaque or -transparent. I think of them as a stop gap measure only useful for masks, and cartoon like GIF images, which use an exact and limited color table (16 colors at most).
For any other image I try to figure out exact what I am wanting to achieve, and try to work out how I want to handle semi-transparent or anti-aliasing pixels which have different colors all along the boundaries.
One example of this is a method of handling a known background removal while preserving shadow and anti-aliasing pixels.
http://www.imagemagick.org/Usage/channe ... antialised
As Rick Cook wrote in his book, "Wizardry Cursed"
It's always the details that get you in trouble.
Re: transparent-color setting
Posted: 2009-01-20T19:01:46-07:00
by rs13
Hmm...
Perhaps a simple example will explain what I am trying to do. I want to run a convert command on the
following image:
http://209.20.87.13/valentines1.png.
When you save that image, you will see that the bear heads are #ffffff color and everything else is transparent. I would like to convert that #ffffff in its entirety to #fffffe. After convert command completes, I would like to have not a single pixel that is #ffffff. Furthermore, I would not like to alter anything else in the images. Any help on this is greatly appreciated.
With Regards,
Robert
Re: transparent-color setting
Posted: 2009-01-20T19:06:16-07:00
by rs13
Also, I should note that I run this convert command in php process using 'exec' command and it is through such processing that the 'ffffe' replacement for 'ffffff' does not happen 100%, as per my earlier comment.
Cheers,
Robert
Re: transparent-color setting
Posted: 2009-01-20T20:23:58-07:00
by anthony
You do know that the image has two white colors!
opaque white and transparent white
you can see this with....
Code: Select all
convert valentines1.png -format %c histogram:info: | head
The
-opaque '#FFFFFF' would only convert opaque white!
Also -transparent-color does not have any meaning in PNG as it is not using a pallette color table like GIF does. do it does NOT effect the transparent white.
Turning off alpha channel then turning it on again afterward got BOTH white colors!
Code: Select all
convert valentines1.png -alpha off -fill '#FFFFFE' -opaque '#FFFFFF' -alpha on result.png
Code: Select all
convert result.png -format %c histogram:info: | head
No more pure white!
See it pays to give an example!
Re: transparent-color setting
Posted: 2009-01-21T23:45:37-07:00
by rs13
Anthony,
Thank you. Your reply was dead on and it solved my problem. Can you please recommend to me some good book in order for me to understand ImageMagick commands and the paradigms of command execution better?
Would you say that a study of a color theory and management is also important?
With Regards,
Robert
Re: transparent-color setting
Posted: 2009-01-22T00:25:48-07:00
by anthony
IM Examples is a good guide, though it is getting rather large.
And getting larger all the time! 'Distort Images' Just split into three!!!
Color Theory and Management, never heard of it. Knwon how RGB colors combine, and how images are usally stored in three color channels, yes that can be a big help. 'Basics' to talk about this.
I suggest you start with Basics, Files, Formats, Canvas, Color then work your way down to more advanced stuff to what you are specifically interested in. I make effort to interlink the pages as much as posible so you can wander around quite a lot!
Re: transparent-color setting
Posted: 2009-01-22T09:21:02-07:00
by rs13
Thanks a million!