473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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?

Thanks!
Jan 13 '06 #1
1 5789
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:an*@doxdesk.com
http://www.doxdesk.com/

Jan 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen Emslie | last post by:
Does anyone know of any python imaging modules that can change the delay between frames of an animated GIF? Thanks Stephen Emslie
0
by: skip | last post by:
I'm unclear how PIL handles multi-frame GIF images. I have such a GIF image in a file, bogus.gif. I can view the individual frames like so (ImageSequence is from the PIL tutorial): ... ...
4
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that...
2
by: moishyyehuda | last post by:
can I download Python Imaging Library (PIL) for linux.
5
by: WT | last post by:
I am trying to crete a gif file with transparent backcolor on the fly but it seems that GDI refuses to do this. I am using samples from Bob Powell but it doesn't seem to work. First create a...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
1
by: David | last post by:
Hello alll, Apologies if this isn't the correct list. I'm getting my feet wet with the Python Imaging Library (PIL) 1.1.6 on Python 2.5.1. I have played around quite a bit with transparent...
1
by: Lawrence D'Oliveiro | last post by:
I'm trying to create PNG files to use in menus for authoring DVDs. As you may know, these menus are only allowed to have limited numbers of colours. Ideally I'd like to create a PNG file with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.