#!/home/chao/anaconda3/envs/test_py2/bin/python
#coding:utf-8
import os
from PIL import Image
def splitimage(src, dstpath):
img = Image.open(src)
w, h = img.size
height=w*297/210 #A4纸比例出的高度
num=h/height+1#将分割出的图片数量
index=0
print height
s = os.path.split(src)#分割出路径和文件名
if dstpath == '':
dstpath = s[0]
fn = s[1].split('.')
basename = fn[0]#文件名
postfix = fn[-1]#后缀名
#print('Original image info: %sx%s, %s, %s' % (w, h, img.format, img.mode))
while (index < num):
print 'The index is:', index,"height is ",height
box = (0, height-1527, w, height)
img.crop(box).save(os.path.join(dstpath, basename + '_' + str(index) + '.' + postfix), img.format)
height = height + 1527
index = index + 1
src="/home/chao/b.png"
dstpath="/home/chao/img"
splitimage(src, dstpath)
#coding:utf-8
import os
from PIL import Image
def splitimage(src, dstpath):
img = Image.open(src)
w, h = img.size
height=w*297/210 #A4纸比例出的高度
num=h/height+1#将分割出的图片数量
index=0
print height
s = os.path.split(src)#分割出路径和文件名
if dstpath == '':
dstpath = s[0]
fn = s[1].split('.')
basename = fn[0]#文件名
postfix = fn[-1]#后缀名
#print('Original image info: %sx%s, %s, %s' % (w, h, img.format, img.mode))
while (index < num):
print 'The index is:', index,"height is ",height
box = (0, height-1527, w, height)
img.crop(box).save(os.path.join(dstpath, basename + '_' + str(index) + '.' + postfix), img.format)
height = height + 1527
index = index + 1
src="/home/chao/b.png"
dstpath="/home/chao/img"
splitimage(src, dstpath)