views:

650

answers:

2

Hi, I have a probably very basic problem with PIL's crop function: The cropped image's colors are totally screwed. Here's the code:

>>> from PIL import Image
>>> img = Image.open('football.jpg')
>>> img
<PIL.JpegImagePlugin.JpegImageFile instance at 0x00
>>> img.format
'JPEG'
>>> img.mode
'RGB'
>>> box = (120,190,400,415)
>>> area = img.crop(box)
>>> area
<PIL.Image._ImageCrop instance at 0x00D56328>
>>> area.format
>>> area.mode
'RGB'
>>> output = open('cropped_football.jpg', 'w')
>>> area.save(output)
>>> output.close()

I can't paste images here as this is my first question, but the original image is here: http://tinyurl.com/cebndm

and the output is here: http://tinyurl.com/cf47ur

As you can see, the output's colors are totally messed up...

Thanks in advance for any help!

-Hoff

+2  A: 

output should be a file name, not a handler.

SilentGhost
+2  A: 

instead of

output = open('cropped_football.jpg', 'w')
area.save(output)
output.close()

just do

area.save('cropped_football.jpg')
fastmultiplication