这是一个全面工作的aswer与一个新版本的PIL 1.1.7。裁剪坐标现在是左上角和右下角(而不是x、y、宽度和高度)。
python的版本号是:2.7.15
对于PIL:1.1.7# -*- coding: utf-8 -*-
from PIL import Image
import PIL, sys
print sys.version, PIL.VERSION
for fn in ['im000001.png']:
center_x = 200
center_y = 500
half_width = 500
half_height = 100
imageObject = Image.open(fn)
#cropped = imageObject.crop((200, 100, 400, 300))
cropped = imageObject.crop((center_x - half_width,
center_y - half_height,
center_x + half_width,
center_y + half_height,
))
cropped.save('crop_' + fn, 'PNG')