pbfy0 / visvis

Automatically exported from code.google.com/p/visvis
Other
0 stars 0 forks source link

images2gif.py handles palettes incorrectly. #81

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
> 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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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