How do I set the transparent-color of a transparent gif?

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
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

How do I set the transparent-color of a transparent gif?

Post by hellocatfood »

I want to upload the following animated gif to flickr. However, when I upload it to there the transparent parts go opaque (the original colour was green (#1cff1a))

Image

I've tried using the following command to set the transparent color to white but it doesn't work
convert a.gif -channel rgba -alpha on -fuzz 35% -transparent "#1cff1a00" -transparent-color white a_modified.gif
Other commands that I've tried either result in a unanimated gifs or completely black gifs. Is there any way that I can do this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

you can set the background color under the transparent parts to black using


convert tANtN.gif -background black -alpha background tANtN_new.gif

See if that works. Probably, the viewer needs to have a black background under the transparent parts. Other wise make the whole background everywhere black.

see
http://www.imagemagick.org/Usage/maskin ... background
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: How do I set the transparent-color of a transparent gif?

Post by hellocatfood »

I changed the command so that it set the background to white

Code: Select all

convert tANtN.gif -background white -alpha background tANtN_new.gif
However, when I upload to flickr I now get a completely black image instead of a green background
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

hellocatfood wrote:I changed the command so that it set the background to white

Code: Select all

convert tANtN.gif -background white -alpha background tANtN_new.gif
However, when I upload to flickr I now get a completely black image instead of a green background

Did you try with a black background?

I am clueless as to what requirements are needed by Flicker with animated gifs.

What version of IM are you using and what platform?

You could try this also:

convert tANtN.gif -alpha off -channel rgb -evaluate set 0 -channel rgba -alpha on tANtN_new.gif

This will make everything in the background black. If you want it to be white (though I don't suggest that), use -evaluate set 100 rather than 0
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: How do I set the transparent-color of a transparent gif?

Post by hellocatfood »

That didn't work either :-(

I may just have to rerender them with a white background instead. It's a shame that Flickr's being so awkward!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

hellocatfood wrote:That didn't work either :-(

I may just have to rerender them with a white background instead. It's a shame that Flickr's being so awkward!

How do you know that Flicker needs a white background. If the above two methods do not work, then making it again with white is not likely to help.

What version of IM and what platform? Perhaps you need to upgrade IM.
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: How do I set the transparent-color of a transparent gif?

Post by hellocatfood »

How do you know that Flicker needs a white background. If the above two methods do not work, then making it again with white is not likely to help.

What version of IM and what platform? Perhaps you need to upgrade IM.[/quote]

From what I can tell Flickr sets the background of any image, transparent or not, to be opaque. I know that by default IM and many other programs set their transparent backgrounds to be transparent black. So far it's all just a bunch of trial and error.

I'm using IM 6.6.9.7-5 on Ubuntu 12.04
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

Your transparent background was green, but the opaque parts were black. In my second method, I set the whole background to black. Some programs like to have the full background image all one color. You can try black or white using the method with -evaluate set. But I am not sure, unless you post your result whether your version of IM has successfully done that.

Is it possible that Flicker does not allow transparent gifs.

You might also try several IM optimize methods. It is also LZW compressed. Perhaps you need to provide either some uncompressed animation or some other compression for Flicker? Perhaps the biggest issue I see is that only the first frame has green background. All the rest have mostly dark background but not perfectly black. I suspect that Flicker needs one common color map, all frames must have the same background color.

You can see that by

convert tANtN.gif -alpha off tANtN_aoff.gif

then play that animation.

See
http://www.imagemagick.org/Usage/anim_opt/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

Looking more carefully at my modifications to the background, for some reason it is not changing the first frame to black even if I add -coalesce. Not sure yet what is going on.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

Looking at your animation in another app and it shows that only the first frame has binary transparency and all the rest of the frames are fully transparent. Thus you only see what is behind which is dark for every frame but the first.

I think you need to remake your animation so that each frame has the appropriate binary alpha channel over either a constant color background or the same background as is in the alpha channel.
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: How do I set the transparent-color of a transparent gif?

Post by hellocatfood »

Here's the results when running

Code: Select all

convert tANtN.gif -alpha off -channel rgb -evaluate set 0 -channel rgba -alpha on tANtN_new.gif
Image

And here's the results when running

Code: Select all

convert tANtN.gif -alpha off -channel rgb -evaluate set 100 -channel rgba -alpha on tANtN_new.gif
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

As I said in my last post, none of those methods seems to work to change the background.

You probably need to recreate the animation from scratch, making sure that each frame has the proper binary alpha channel for that frame and that the background matches or is totally black.

Try this:

convert tANtN.gif -coalesce -alpha off tANtN_aoff.gif

You will see that only the first frame show the green background with black letter a. The rest of the channels are nearly solid black.

Then try this:

convert tANtN.gif -coalesce -alpha extract tANtN_alpha.gif

It will show you each alpha channel, which are correct.


Somehow you need to extract the alpha channels, create a black background for each and the put the alpha channels back. I am not an expert on animations and do not understand why my earlier methods do not work nor how to fix your animation.

Perhaps Anthony will see this post and can suggest a better process.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I set the transparent-color of a transparent gif?

Post by fmw42 »

This works fine to change the background color in my fake animation:


convert logo: -transparent white -duplicate 3 logo_4f.gif
convert logo_4f.gif -alpha off logo_4f_aoff.gif
convert logo_4f.gif -coalesce -alpha off -evaluate set 0 -alpha on logo_4f_black.gif
convert logo_4f_black.gif -alpha off logo_4f_black_aoff.gif


I think it does not work in your animation, because the background color set in each frame of the animation is fixed and I cannot change it. Look at each frame and you will see that the first frame has background color different from the others.

All the frames say:
Background color: white

except for the first, which says:
Background color: srgba(28,255,26,1)
which is your green color.

I do not know how to override that value.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How do I set the transparent-color of a transparent gif?

Post by anthony »

going back to basics (wish the example was smaller!)
removing transparency of each frame (set to images background color) before append/resize

Code: Select all

convert tANtN.gif'[0-10]' -coalesce -alpha remove +append -resize 1600x show:
shows that the per-image background color is green for the first frame, but white for all other frames.

If you append then remove transparency, the background color setting from the first frame will be used for the single image (everything green)

Code: Select all

convert tANtN.gif'[0-10]' -coalesce +append -alpha remove -resize 1600x show:
To just reset the background color for ALL images use this
convert tANtN.gif -background white -transparent-color white tANtN_mod.gif



After checking with the GIF specific content viewer "giftrans" (Download from http://www.ict.griffith.edu.au/anthony/ ... /#giftrans )

Code: Select all

giftrans -L tANtN.gif 
background color = index 0 (green)
Transparent Color Flag = true
Transparent Color Index: 1 (also green)
But later frames switch to local color tables. with different colors and settings,

There is LOTS of colors in this supposedly simple boolean (on/off) image.

As such to clean this up to be properly to use just 2 color boolean black on white (just alpha)

Code: Select all

convert tANtN.gif -coalesce -alpha extract -negate tANtN_bw.gif
I could have also added +remap, to ensure one global colortable is used. but IM figures that is all that is needed automatically in this case. There is not transparency so background and transparency settings is not needed.
I also doubt frame optimization will get you much improvement in compression for this simple 2 color GIF.

If you wanted smooth anti-aliases edges using GIF with transparency was a bad choice. You have lost a lot of info due to the GIF boolean transparency. The animation should be re-created using pure grayscale and without transparency to create a better GIF animation of the letter. Also when generating the GIF use +remap to use a single global grayscale colortable.

IM really needs some way of setting GIF colortables more exactly, without 'skipping' unused colors, or re-arranging the colors in that colortable. This is something I mentioned for IMv7 development, but it is low prioity.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply