Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, <code>JPEG</code> doesn't support transparency! But that's not the only problem.. As you move to the next frame of the <code>GIF</code> the <code>palette</code> information is lost (<a href="http://mail.python.org/pipermail/image-sig/2008-November/005273.html" rel="noreferrer">problem witn PIL?</a>) - so <code>PIL</code> is unable to correctly convert to the <code>RGBA</code> framework (Hence the first frame is okish, but all the others are screwy). So the work-around is to add the <code>palette</code> back in for every frame, (which is what you were doing in your last code example, but your trouble was that you were saving as <code>RGB</code> not <code>RGBA</code> so you had no alpha/ transparency channel. Also you were doing a few unnecessary things..). Anyhow, here are the .png's with transparency and the corrected code, hope its of some use :)</p> <p><img src="https://i.stack.imgur.com/KCD9p.png" alt="enter image description here"><img src="https://i.stack.imgur.com/SAu7p.png" alt="enter image description here"><img src="https://i.stack.imgur.com/g0Lfo.png" alt="enter image description here"><img src="https://i.stack.imgur.com/00AAc.png" alt="enter image description here"><img src="https://i.stack.imgur.com/2c17L.png" alt="enter image description here"><img src="https://i.stack.imgur.com/nutsv.png" alt="enter image description here"><img src="https://i.stack.imgur.com/d6n3T.png" alt="enter image description here"><img src="https://i.stack.imgur.com/V13hc.png" alt="enter image description here"><img src="https://i.stack.imgur.com/jWywv.png" alt="enter image description here"><img src="https://i.stack.imgur.com/4dlAK.png" alt="enter image description here"></p> <pre><code>import Image import sys def processImage(infile): try: im = Image.open(infile) except IOError: print "Cant load", infile sys.exit(1) i = 0 mypalette = im.getpalette() try: while 1: im.putpalette(mypalette) new_im = Image.new("RGBA", im.size) new_im.paste(im) new_im.save('foo'+str(i)+'.png') i += 1 im.seek(im.tell() + 1) except EOFError: pass # end of sequence processImage('gif_example.gif') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload