PIL 1.1.6 saves Photoshop CMYK image color

I have an image . I want to change it using PIL, but it comes out like this .

Even without resizing, it still messed up the color .

Minimum 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" formats, but still get weird or gray results.

When I load the image from the hard drive I 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 more details.

+2


a source to share


4 answers


Following the interjay link, the issue was fixed by updating to PIL 1.1.7 . This includes an update to allow Photoshop-generated CMYK JPEGs to work properly. But don't blame PIL, as Fredrik Lund puts it :

"CMYK in JPEG is one big mess, mainly because Adobe got it wrong with Photoshop a few years ago."

By the way, you can find which version of PIL you have:



>>> Image.VERSION  
'1.1.7'  

      

Refresh . To make the resulting image in IE, you need to add .convert('RGB')

so that you output in standard JPEG RGB, not CMYK.

+4


a source


PIL seems to have a problem loading some CMYK JPEG files. If you can convert the image to a more widely supported color format (using another tool) that will help.



There's a PIL patch posted here , but I haven't tried it.

+2


a source


I had problems like this when the original image was saved in CMYK mode. I had to save the image in RGB before I could process it with PIL.

+1


a source


Highly recommend if you have Photoshop to change the color settings. These can be toggled to warn you of mismatched or missing color profiles.

See how to install this: http://www.flickr.com/photos/kaichanvong/5979227438/in/photostream

Was interesting today when the image didn't have a color profile attached to it and thought it was in CMYK - the photo would get inverted colors.

Didn't notice this at first on Lion, but became apparent on iPad / other machines. Very strange.

If you have the mismatch / missing profile option enabled, you can tell Photoshop to add the default version. I understand that this is not the final solution ... but it should help you understand the problem better.

Converting to RGB is not an option in this case as colors are not being replicated properly - eg. radioactive hulk like green

0


a source







All Articles