图片切割
import os
from PIL import Image
for i in range(0, 350):
print(i)
src = 'img/'+str(i)+'.jpeg'
img = Image.open(src)
w, h = img.size
if 1 <= h and 2 <= w:
s = os.path.split(src)
fn = s[1].split('.')
print(fn)
basename = fn[0]
ext = fn[-1]
num = 0
rowheight = h // 1
colwidth = w // 2
for r in range(1):
for c in range(2):
box = (c * colwidth, r * rowheight, (c + 1) * colwidth, (r + 1) * rowheight)
img.crop(box).save(os.path.join(basename + '_' + str(num) + '.' + ext), ext)
num = num + 1
print('图片切割完毕,共生成 %s 张小图片。' % num)