import os
from PIL import Image

PATH = 'D:/tensorflow/未处理的训练源/'
PATH2 = 'D:/tensorflow/train/'

def resize_image(img_path,save_path):
    total = 0
    try:
       for pic in os.listdir(img_path):
           path = img_path+pic
           image = Image.open(path).convert('L')
           new_pic = image.resize((60,60),Image.ANTIALIAS)
           new_path = save_path+str(total)+'.jpg'
           new_pic.save(new_path,quality=100)
           total = total+1

    except Exception as e:
        print(e)

if __name__ == '__main__':
    for page in range(1,6):
        print("During deal with %d"%(page))
        resize_image(PATH+str(page)+'/',PATH2+str(page)+'/')