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)
Remove transparency in GIF's?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Remove transparency in GIF's?
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Remove transparency in GIF's?
Then you have to extract the color first? using: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.
identify -verbose $src | grep '^ Alpha:'
Or is there an easier way? setting the color directly, something like:
-background transparentcolor
It looks as they mostly have suitable colors. If there are some with bad colors they can be manually handled. We'll see.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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Remove transparency in GIF's?
Fair enough...
So, remove the alpha/matte channel, immediately after reading the image, before doing any other processing.
So, remove the alpha/matte channel, immediately after reading the image, before doing any other processing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/