裁剪图片

# 导入相关的库
from PIL import Image

# 打开一张图
img = Image.open('.\longzhong.png')
# 图片尺寸
img_size = img.size
h = img_size[1] # 图片高度
w = img_size[0] # 图片宽度
print(h,w)

x = 0.573* w #左
y = 0.543 * h #上
w = 0.1025 * w #图片宽
h = 0.0417 * h #图片高
print(x,y,w,h)
# 开始截取
region = img.crop((x, y, x + w, y + h))
# 保存图片
region.save("test.png")

猜你喜欢

转载自www.cnblogs.com/xdlzs/p/10743014.html
今日推荐