[英]Why doesn't PIL/Pillow crop work?
I'm trying to use Pillow to crop an image, but it doesn't seem to work. 我正在尝试使用枕头来裁剪图像,但是它似乎不起作用。 I've got the following code:
我有以下代码:
im = Image.open('the_image.jpg')
print 'ORIGINAL SIZE: ', im.size
im.crop((1087, 0, 1820, 2197))
print 'CROPPED SIZE: ', im.size
which prints this in the terminal: 在终端上打印此:
ORIGINAL SIZE: (2908, 2197)
CROPPED SIZE: (2908, 2197)
Does anybody know why the cropping doesn't seem to work? 有人知道为什么种植似乎无效吗? All tips are welcome!
欢迎所有提示!
Its because of that im.crop((1087, 0, 1820, 2197))
doesn't crop your image in-place but it returns the cropped image. 因此,
im.crop((1087, 0, 1820, 2197))
不会就地裁剪图像,但会返回裁剪后的图像。
You can do : 你可以做 :
im = Image.open('the_image.jpg')
print 'ORIGINAL SIZE: ', im.size
cr=im.crop((1087, 0, 1820, 2197))
print 'CROPPED SIZE: ', cr.size
或者你可以做
im.crop((1087, 0, 1820, 2197)).save('the_image.jpg','jpeg')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.