Page 1 of 1

Remove transparency in GIF's?

Posted: 2008-06-14T02:20:05-07:00
by SwedeMan
Hi,

how to remove the transparency in GIFs, keeping the color used for the transparency in each GIF?

Edit:
Solution:
convert myimage.gif -alpha off myimage.gif

(or +matte)

Re: Remove transparency in GIF's?

Posted: 2008-06-14T21:51:14-07:00
by anthony
Very good.

However as an addendum (there always an addendum!)...

IM goes to great pains to allow you to re-use a existing opaque color, as the transparent color.

That is you can use both opaque white, but specify that white is the 'transparent color' for the image. As such just turning off the transparency in the image would also merge these two colors, making them indistinguishable.

Also ANY modification of the image before turning off the alpha channel, could make the transparent color that is stored in the image data black! This is because to IM transparent is transparent and color has not meaning when a pixel is transparent. The math of some operators then resets transparent pixels black (all zero). As such you method will only work if it is the first thing you do after reading a GIF image.

The BEST way is to set the transparency color as 'background' and flatten the image. That will guarantee the setting of transparent pixels correctly even after performing some image processing.

Finally, most GIF images are assigned a random 'transparent' color, depending on the application which generated it, as it is supposed to be of no consequence. I would not relay on the default color being very nice looking.

See IM examples, GIF transparency Color
http://imagemagick.org/Usage/formats/#gif_trans
Which goes though all this.

Re: Remove transparency in GIF's?

Posted: 2008-06-15T03:18:22-07:00
by SwedeMan
anthony wrote:The BEST way is to set the transparency color as 'background' and flatten the image. That will guarantee the setting of transparent pixels correctly even after performing some image processing.
Then you have to extract the color first? using:
identify -verbose $src | grep '^ Alpha:'
Or is there an easier way? setting the color directly, something like:
-background transparentcolor
anthony wrote:Finally, most GIF images are assigned a random 'transparent' color, depending on the application which generated it, as it is supposed to be of no consequence. I would not relay on the default color being very nice looking.
It looks as they mostly have suitable colors. If there are some with bad colors they can be manually handled. We'll see.

Re: Remove transparency in GIF's?

Posted: 2008-06-15T17:16:01-07:00
by anthony
Fair enough...

So, remove the alpha/matte channel, immediately after reading the image, before doing any other processing.