在python中使用PIL裁剪图像
答
您需要导入PIL(枕头)这一点。 假设你有1200尺寸的图像,1600年我们将裁剪图像从400,400到800,800
from PIL import Image
img = Image.open("ImageName.jpg")
area = (400, 400, 800, 800)
cropped_img = img.crop(area)
cropped_img.show()
是的,我知道,im.crop(盒)用于裁切图像。但我只想裁剪图像的上下部分,尽管box()需要4个元组,但我不知道如何裁剪图像的上部和下部。 – 2012-04-02 20:43:24
@TajKoyal:ninjagecko正在向你展示的是你如何从顶部和底部切下。他正在为新图像指定一个矩形。你可以看到他从顶点和底点上的y值减去30个像素。如果以任何方式抵消x值,那么会影响左侧和右侧。 – jdi 2012-04-02 21:24:52
谢谢你帮助我。 – 2012-04-03 09:41:21