我想通过从给定的图像中删除前30行和最后30行来裁剪图像。我已经找过了,但没有得到确切的答案。有人有什么建议吗?
发布于 2012-04-03 04:29:22
有一个crop()
方法:
w, h = yourImage.size
yourImage.crop((0, 30, w, h-30)).save(...)
发布于 2017-04-24 23:02:29
为此,您需要导入PIL (Pillow)。假设你有一个大小为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()
发布于 2019-01-18 05:23:40
一种更简单的方法是使用ImageOps中的裁剪。您可以输入要从每一面裁剪的像素数。
from PIL import ImageOps
border = (0, 30, 0, 30) # left, top, right, bottom
ImageOps.crop(img, border)
https://stackoverflow.com/questions/9983263
复制相似问题