The crop
function is actually lazy, meaning the cropping doesn't happen until you try to access the pixels, which in your case happens during the save
.
You can force it to happen eagerly by calling load
:
>>> im = im.crop(points)
>>> im
<PIL.Image._ImageCrop image mode=CMYK size=32x85 at 02630B48>
>>> im.load()
<PixelAccess at 0x108d2ba70>
>>> im.save("new_image.tif")
I initially suggested this as a way to help debug the problem, because there are three things that could happen:
- If
load
crashes, the problem is in forcing evaluation of the crop. - If
load
succeeds, butsave
crashes, the problem is in saving (certain) TIFF images. - If they both succeed… the first possibilities that come to mind are that you don't have enough memory to keep the cropped and uncropped versions around simultaneously, or there's a bug somewhere in the way
save
triggers evaluation of lazy functions.
Of course in option 3, if you're just trying to get past this for a one-shot task, you may not care about debugging further. But there's a good chance it'll pop up again with a different image, so if you're trying to build a program for wider use, it's better to continue debugging the problem (starting with getting the stack trace from a crash dump).
See the docs for more details on all of the functions described above.