Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python and PIL pixel values different for GIF and JPEG

I have a question about the pixel values returned from an image opened with PIL load function. I am using the following code:

frame = Image.open(fname).load()
a = frame[10, 10]

If I load a GIF image, a is the integer value 43. But if I convert the image a JPEG and rerun the code, a is a tuple (253, 254, 100).

Why? And how can i convert (253, 254, 100) back to 43?

like image 307
alex Avatar asked Apr 27 '11 05:04

alex


1 Answers

GIFs are pallettized, whereas JPEGs are RGB. The act of transforming the image disposes of the palette, so you will have to look through the pallette entries in the GIF to find the closest match to the desired color.

like image 84
Ignacio Vazquez-Abrams Avatar answered Oct 31 '22 12:10

Ignacio Vazquez-Abrams