PIL saves image colour wrong

Posted by Tom Viner on Stack Overflow See other posts from Stack Overflow or by Tom Viner
Published on 2010-04-19T12:11:16Z Indexed on 2010/04/19 12:13 UTC
Read the original article Hit count: 355

Filed under:
|
|

I have an image. I want to resize it using PIL, but it come out like this.

Even without a resize it still messes up the colour.

Minimal code:

from PIL import Image
import os
import urllib
import webbrowser

orig_url = 'http://mercedesclub.org.uk/images/stackoverflow-question/least-popular-colours-_-500-x-500.jpg'
temp_fn, _ = urllib.urlretrieve(orig_url)

im = Image.open(temp_fn)

fn = os.tempnam() + '.jpg'
im.save(fn)
webbrowser.open(fn)

I've tried Image.open(temp_fn).convert(format) with 'RGB', 'CMYK' and 'L' as formats, but still get weirdly coloured or grey results.

When I load the image from my hard drive and I can see:

>>>im.info  
{'adobe': 100, 
'progression': 1, 
'exif': 'Exif\x00\x00MM\x00*...\x7f\xff\xd9', 
'adobe_transform': 100}

>>>im.format  
'JPEG'  

>>>im.mode  
'CMYK'  

>>> im._getexif()
{40961: 65535, 40962: 500, 40963: 500, 296: 2, 34665: 164, 274: 1, 305: 'Adobe Photoshop CS Macintosh', 306: '2010:02:26 12:46:54', 282: (300, 1), 283: (300, 1)}

Thanks and let me know if you need any more data.

© Stack Overflow or respective owner

Related posts about pil

Related posts about image