为什么PIL /枕式作物不起作用?

kra*_*r65 2 python image crop python-imaging-library pillow

我正在尝试使用枕头来裁剪图像,但是它似乎不起作用。我有以下代码:

im = Image.open('the_image.jpg')
print 'ORIGINAL SIZE: ', im.size
im.crop((1087, 0, 1820, 2197))
print 'CROPPED SIZE: ', im.size
Run Code Online (Sandbox Code Playgroud)

在终端上打印此:

ORIGINAL SIZE:  (2908, 2197)
CROPPED SIZE:  (2908, 2197)
Run Code Online (Sandbox Code Playgroud)

有人知道为什么种植似乎无效吗?欢迎所有提示!

Kas*_*mvd 5

因此,它im.crop((1087, 0, 1820, 2197))不会原位裁剪图像,但会返回裁剪后的图像。

你可以做 :

im = Image.open('the_image.jpg')
print 'ORIGINAL SIZE: ', im.size
cr=im.crop((1087, 0, 1820, 2197))
print 'CROPPED SIZE: ', cr.size
Run Code Online (Sandbox Code Playgroud)

  • 这很奇怪,因为`im.thumbnail()`确实会调整大小。好吧,它现在可以工作了.. :-)谢谢百万! (2认同)