any lib to convert 3200+ pic to animated gif?

Chris Angelico rosuav at gmail.com
Sat Nov 30 09:38:43 EST 2013


On Sun, Dec 1, 2013 at 1:21 AM, oyster <lepto.python at gmail.com> wrote:
> I want to make an animated GIF from 3200+ png
> I searched and found http://code.google.com/p/visvis/source/browse/#hg/vvmovie
> and I wrote:
> allPic=glob.glob('*.png')
> allPic.sort()
> allPic=[Image.open(i) for i in allPic]
> writeGif('lala3.gif',allPic, duration=0.5, dither=0)
>
> However I got
> IOError: [Errno 24] Too many open files: 'out0572.png'

Yes, trying to open 3200 files is likely to be a problem!

The question is, how can you load them into memory one by one, and
keep closing them? I'm not very familiar with PIL, but a glance at the
code suggests that the Image.open() calls will create, but possibly
not verify, the images. Does this work?

images = []
for pic in allPic:
    img = Image.open(pic)
    img.verify()
    images.append(img)
allPic = images

Use that instead of your list comprehension. In theory, at least, that
should abandon the file objects (not explicitly closing them, alas,
but abandoning them should result in them being closed in CPython), so
you ought to get them all opened and read.

Otherwise, someone with more knowledge of PIL may be able to help.
According to the PIL docs, this list may be more focussed on what
you're trying to do, so if you don't get a response here, try there:

https://mail.python.org/mailman/listinfo/image-sig

Hope that helps!

ChrisA



More information about the Python-list mailing list