color JPEGs

Paul Barrett Barrett at STScI.Edu
Fri Sep 24 10:17:23 EDT 1999


I'm trying to create a color JPEG from Numeric data.  I used Rob Hooft's
message from earlier this year to get me started.  All of his code
appears to work fine.  The problem appears when I try to save the image,
i.e. img.save('filename.jpg'). I get  the following error message:

IOError: cannot write mode P as JPEG

Can a PIL guru tell me what I'm doing wrong and how to proceed? I've
attached the relevant python code to help.

img = Image.Palette('P', (data.shape[1], data.shape[0]),
data.tostring(), 'raw', 'P')
img.palette = ImagePalette.raw('RGB', string.join(palette, ''))
img.save('filename')

-- Paul








More information about the Python-list mailing list