代码如下:
from PIL import Image
im = Image.open("img/b.jpg")
# 图片的宽度和高度
img_size = im.size
print("图片宽度和高度分别是{}".format(img_size))
xx = 6
yy = 4
x = img_size[0] // xx
y = img_size[1] // yy
for j in range(yy):
for i in range(xx):
left = i*x
up = y*j
right = left + x
low = up + y
region = im.crop((left,up,right,low))
print((left,up,right,low))
temp = str(i+1)+'-'+str(j+1)
region.save("img2/"+temp+".jpg")
按着横纵轴均匀裁剪