【问题标题】:How to set coordinates when cropping an image with PIL?使用 PIL 裁剪图像时如何设置坐标?
【发布时间】:2017-01-18 08:11:13
【问题描述】:

我不知道如何设置坐标以在PILs crop() 中裁剪图像:

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

我尝试使用gThumb 获取坐标,但如果我要裁剪一个区域,我只能找到位置 194 336。有人可以帮我吗?

这是我的照片:

我想剪成这样:

【问题讨论】:

    标签: python image python-2.7 python-3.x image-processing


    【解决方案1】:

    如何设置裁剪坐标

    行内:

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

    前两个数字定义出风口的左上角坐标 (x,y),而后两个数字定义出风口的右下角坐标。

    裁剪图像

    为了像您展示的那样裁剪图像,我找到了以下坐标:左上角:(200, 330),右下角:(730, 606)。随后,我将您的图像裁剪为:

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

    结果:

    【讨论】:

    • 但我按下了箭头。这不是“接受”吗?我真蠢。真的不知道怎么办:(
    • 好的。谢谢你。我终于找到了。对不起,我不知道。感谢您的大力帮助:)
    猜你喜欢
    • 2012-04-16
    • 2016-12-09
    • 1970-01-01
    • 2018-12-11
    • 2019-03-26
    • 2021-11-06
    • 2021-09-01
    • 2012-10-01
    相关资源
    最近更新 更多