transparent-color setting

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
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

transparent-color setting

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

Re: transparent-color setting

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

Re: transparent-color setting

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

Re: transparent-color setting

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

Re: transparent-color setting

Post 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
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

Re: transparent-color setting

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

Re: transparent-color setting

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

Re: transparent-color setting

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

Re: transparent-color setting

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rs13
Posts: 65
Joined: 2009-01-15T12:57:26-07:00

Re: transparent-color setting

Post by rs13 »

Thanks a million!
Post Reply