2

Edit: The problem with my original search for information was that I did not distinguish between gifs and "animated gifs". Hence there are a lot of resources on SO to deal with this question. Resources: Link 3

Evidently PIL itself is poorly equipped to deal with animated gifs.

I'm trying to convert gif frames to jpg. For some gifs (mostly black and white) this works out fine, but for others (mostly color) not so much. I've looked at a few of the posts on SO, and tried them, to no avail. In particular I tried out: Link1 , Link2.

Performance is a mild consideration, but for now I'd just like a working solution. A consistent pattern is that the first image of the gif will always come out perfect. Interestingly enough, I have even tried out Zamzar and it also produces the same noise data. I was doing some research and it seems that this might be an issue with the LZW compression algorithm, though on SO, I've seen posts that suggest PIL takes care of LZW decompression. On the other hand I've heard that LZW decompression is propitiatory.

Note that I've also tried converting to PNG without success there either. Are the white dots layered on top of the image or something?

Here is a sample gif that produces this error.

Edit: I just came across images2gif.py. I will update this post if it works for this problem.

Here is the code I'm using:

from PIL import Image
import sys
import os

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("RGB", im.size)

            #new_im = Image.new("RGB", im.size)
            new_im.paste(im)
            new_im.save('foo'+str(i)+'.png')
            #if(os.stat('foo' + str(i)+'.png')):
                # os.remove('foo' + str(i) + '.jpg')
             i += 1
             mypalette = im.getpalette()
             im.seek(im.tell() + 1)

     except EOFError:
         pass # end of sequence
Cœur
  • 37,241
  • 25
  • 195
  • 267
Rishi
  • 141
  • 7
  • 3
    At StackOverflow, instead of putting "Solved" in the title, please can you post your solution in the answer box to help others? – Hugo May 11 '14 at 20:35

0 Answers0