Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images2gif.py handles palettes incorrectly. #81

Closed
GoogleCodeExporter opened this issue Sep 1, 2015 · 9 comments
Closed

images2gif.py handles palettes incorrectly. #81

GoogleCodeExporter opened this issue Sep 1, 2015 · 9 comments

Comments

@GoogleCodeExporter
Copy link

I'm using the release version of Pillow, the active development branch of PIL, 
with images2gif.py.

There are three issues here.

First, please see 
https://code.google.com/p/visvis/source/browse/vvmovie/images2gif.py#413

> palette = getheader(im)[1]

In personal communication with wiredfool from the PIL, we looked through the 
PIL code and established that the palette is in fact in getheader(im)[0][-1]


Second, the fallback palette is, from 
https://code.google.com/p/visvis/source/browse/vvmovie/images2gif.py#415

> palette = PIL.ImagePalette.ImageColor

But this is a module, and not appropriate for a color palette!

The correct solution would be to use PIL.Image.convert(mode='P') to convert the 
image to palette mode.  My client code converts everything to mode='P' already 
so I didn't test this.


Finally, there are .encode('utf-8') calls scattered around the code.  These 
won't work - the data given to you by PIL is already in bytes format.  Just 
deleting them seems to be effective.

With those changes, I was able to get this routine to write nice-looking 
animated GIFs!

Original issue reported on code.google.com by tom.ritc...@gmail.com on 24 Feb 2014 at 11:10

@GoogleCodeExporter
Copy link
Author

> Finally, there are .encode('utf-8') calls scattered around the code.  These 
won't work - the data given to you by PIL is already in bytes format. 

Also on Python 3?

Original comment by almar.klein@gmail.com on 27 Feb 2014 at 3:23

@GoogleCodeExporter
Copy link
Author

I am trying to fix things, bug get nothing bet errors from PIL, using up to 
date Ubuntu. I am working on alternative solution that does not rely on PIL, so 
I am not going to waste any more time on this ... sorry

Original comment by almar.klein@gmail.com on 27 Feb 2014 at 3:41

@GoogleCodeExporter
Copy link
Author

I managed to get it working pretty fast, so it's definitely doable.

https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py

PIL isn't being actively developed, you should be using Pillow, the active
fork:  http://pillow.readthedocs.org/en/latest/

These strings are actually bytes - you shouldn't have to use encodings on
any version of Python.

If you're going to abandon PIL/Pillow, I'm curious as to what you're going
to use?  As far as I know, there isn't another general purpose image
library for Python...

Original comment by tom.ritc...@gmail.com on 27 Feb 2014 at 4:16

@GoogleCodeExporter
Copy link
Author

Yes, I meant I am using the latest Pillow. But even then it seems the API and 
behavior changes. With your versions it also does not work (probably because 
Pillow version is different) and it produces a corrupt gif.

I am working on imageio (https://github.com/imageio/imageio), which I forked 
from an image io plugin in scikit-image. It used freeimage for all common file 
formats. Development is not going very fast, because I don't have much time for 
it, but it's quite stable and powerful. I could use some help in developing it 
further :)


Original comment by almar.klein@gmail.com on 3 Mar 2014 at 9:26

@GoogleCodeExporter
Copy link
Author

Oh, that looks like a very interesting project!

If this handled animated GIFs, it'd be perrrfect for my current project -
https://github.com/rec/echomesh/

I'm tempted to get involved but :-/ I'm involved in a few too many *and* I
have an actual job coming up.  But if you get to animated GIF success, drop
me a line and I'll move to using yours, I'm not happy using a hacked piece
of old software... :-)

Original comment by tom.ritc...@gmail.com on 4 Mar 2014 at 7:40

@GoogleCodeExporter
Copy link
Author

Thank you so much. I used the `images2gif.py` from [echomesh's 
project](https://github.com/rec/echomesh/blob/master/code/python/external/images
2gif.py) and my problem is fixed!

Original comment by bleeding...@gmail.com on 27 May 2014 at 10:27

@vic1309
Copy link

vic1309 commented Mar 2, 2016

Guys, I'm still having the problem of:

TypeError: must be string or buffer, not None

Here is my code:

from PIL import Image, ImageSequence
import glob
from images2gif import writeGif
import numpy as np

a = np.sort(glob.glob(r'C:\User\lalala\anim*.bmp'))
images = [Image.open(fn) for fn in a]
writeGif('teste.gif',images,duration=0.2)

@almarklein
Copy link
Owner

@vic1309 what images2gif is that? The one from visvis or the one linked above? Have you tried imageio yet. It's much more stable since I mentioned it earlier in this thread.

@almarklein
Copy link
Owner

almarklein commented May 30, 2017

Closing. Please use imageio instead, and report any problems in https://github.com/imageio/imageio/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants