Re: Retrieve a GIF's palette entries using Python Imaging Library (PIL)



Stuart wrote:

> I see that the 'Image' class has a 'palette' attribute which returns an
> object of type 'ImagePalette'. However, the documentation is a bit
> lacking regarding how to maniuplate the ImagePalette class to retrieve
> the palette entries' RGB values.

ImagePalette.getdata() should do it.

There seems to be some kind of bug, however, where Images lose their
ImagePalettes after being convert()ed to paletted images (eg. using
Image.ADAPTIVE). For this reason I personally use the getpalette()
method from the wrapped image object, which seems to contain the proper
raw palette data. For example to get a list of [r,g,b] colour lists:

def chunk(seq, size):
return [seq[i:i+size] for i in range(0, len(seq), size)]

palette= image.im.getpalette()
colours= [map(ord, bytes) for bytes in chunk(palette, 3)]

--
And Clover
mailto:and@xxxxxxxxxxx
http://www.doxdesk.com/

.



Relevant Pages

  • Re: Set color of points in PGN term?
    ... What do you mean by "set color mapping" and which commands in the demo ... I assume you've already refered to the documentation, ... splot "my.data" lt palette ... but I just want a 2D plot. ...
    (comp.graphics.apps.gnuplot)
  • Re: Can 5.2 Mathematica book be installed in 6?
    ... Even without updates it would be nice, ... documentation, it is just not arranged nicely into sections. ... someone has posted to MathGroup a palette with ... search the MathGroup archives for it. ...
    (sci.math.symbolic)