Skip to content Skip to sidebar Skip to footer

Transparency Not Working Consistently While Saving GIF's In PIL

I am working on script that writes over images and makes the background transparent. Output is supposed to be in GIF format. The script works but for certain images the transparen

Solution 1:

The problem is that your "original image" contains the same index-color that the GIFs use to signify "this pixel is transparent".

Gifs are "palette-based" - one index into this palette is designated as "this is transparent" (see f.e. https://en.wikipedia.org/wiki/GIF)

So if you specify pure black or pure white as color-index that is transparent and your sourceimage already contains pixels with this exact color, they get to be transperent as well.

To avoid this, you could sample your source background-image and choose a "non-existent" color as transparency-color - this would never get to be in your resulting image.

You could also change your source images pixel values - check all pixel and change all "background-ones" a tiny fraction off so they do not get translucent.


Post a Comment for "Transparency Not Working Consistently While Saving GIF's In PIL"