Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's PIL crop problem: color of cropped image screwed

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()

The original image: enter image description here

and the output.

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

Thanks in advance for any help!

-Hoff

like image 980
Hoff Avatar asked Feb 28 '23 18:02

Hoff


1 Answers

output should be a file name, not a handler.

like image 130
SilentGhost Avatar answered Mar 06 '23 21:03

SilentGhost