简体   繁体   English

使用 PIL 裁剪图像时如何设置坐标?

[英]How to set coordinates when cropping an image with PIL?

I don't know how to set the coordinates to crop an image in PIL s crop() :我不知道如何设置坐标以在PILcrop()中裁剪图像:

from PIL import Image
img = Image.open("Supernatural.xlsxscreenshot.png")
img2 = img.crop((0, 0, 201, 335))
img2.save("img2.jpg")

I tried with gThumb to get coordinates, but if I take an area which I would like to crop, I can only find position 194 336. Could someone help me please?我尝试使用gThumb获取坐标,但如果我选择一个我想裁剪的区域,我只能找到 position 194 336。有人可以帮我吗?

This is my picture:这是我的照片:

在此处输入图像描述

I wish to crop to this:我想裁剪成这样:

在此处输入图像描述

How to set the coordinates to crop如何设置要裁剪的坐标

In the line:在行中:

img2 = img.crop((0, 0, 201, 335))

the first two numbers define the top-left coordinates of the outtake (x,y), while the last two define the right-bottom coordinates of the outtake.前两个数字定义了出口的左上角坐标 (x,y),而后两个数字定义了出口的右下角坐标。

Cropping your image裁剪您的图像

To crop your image like you show, I found the following coordinates: top-left: (200, 330) , and right-bottom: (730, 606) .为了像您展示的那样裁剪图像,我找到了以下坐标:左上角: (200, 330)和右下角: (730, 606) Subsequently, I cropped your image with:随后,我用以下方法裁剪了您的图像:

img2 = img.crop((200, 330, 730, 606))

在此处输入图片说明

with the result:结果:

在此处输入图片说明

@Jacob Vlijm thankx for the great explanation. @Jacob Vlijm 感谢您的精彩解释。

But, those who are in hurry or are stupid like me - here is an abstraction-:)但是,那些匆忙或像我一样愚蠢的人 - 这是一个抽象 - :)

python枕头坐标系抽象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM