from PIL import Image
import os,sys
width,height=945,1280
if len(sys.argv)<2:
print('python cutpic.py xxx.jpg')
sys.exit(2)
file = sys.argv[1]
img = Image.open(file)
rgb_img = img.convert('RGB')
pic_width,pic_height=rgb_img.size
copy=int(pic_height/height+0.99999)
print('文件名:%s\t宽:%s\t高:%s\t,被切成%s个文件.'%(file,pic_width,pic_height,copy))
filename = os.path.splitext(file)[0]
for i in range(0,copy):
left = 0
upper = i*height
right = width
lower = (i+1)*height
if i == copy-1:
lower = int(pic_height)
cropped = rgb_img.crop((left, upper, right, lower))
savefile = filename+'_'+str(i)+'.jpg'
print("切割为:",savefile)
cropped.save(savefile)