[Image-SIG] Retrieve a GIF's palette entries using Python Imaging Library (PIL)

Stuart White stuart.white1 at gmail.com
Sat Jan 14 05:26:48 CET 2006


I''ll answer my own question.  Here's what I was looking for:

   lut = im.resize((256, 1))
   lut.putdata(range(256))
   lut = list(lut.convert("RGB").getdata())
   print lut


On 1/13/06, Stuart White <stuart.white1 at gmail.com> wrote:
> Thank you for posting this response.  It is indeed a thorough
> discussion of what a palette is and how to set it.
>
> I'm looking for a way to *retrieve* an image's palette (without
> modifying it in any way).  So, I definitely don't want to use
> putpalette().  A "palette" attribute exists in the "Image" class that
> returns an object of type "ImagePalette", but for the life of me, I
> can't figure out how to use this object to retrieve the image's
> palette RGB values.  And I can't seem to find anything by Googling
> either.
>
> On 1/13/06, Terry Carroll <carroll at tjc.com> wrote:
> > On Fri, 13 Jan 2006, Stuart White wrote:
> >
> > > I am using the Python Imaging Library (PIL) to process GIF images. I
> > > need to be able to retrieve the RGB values for each color palette entry.
> > >
> > > 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.  Can anyone point me to a short example?
> >
> > There was a very helpful discussion on this topic on Python-tutor last
> > summer.  Check out the thread "PIL's palette" at this URL:
> >
> > http://mail.python.org/pipermail/tutor/2005-July/thread.html#39719
> >
> > _______________________________________________
> > Image-SIG maillist  -  Image-SIG at python.org
> > http://mail.python.org/mailman/listinfo/image-sig
> >
>


More information about the Image-SIG mailing list