工作生活

figure resize

2019-07-15  本文已影响0人  狼无雨雪
#encoding:utf-8 

## Used to resize pictures
import os
import re
import os.path
from PIL import Image
# Image.MAX_IMAGE_PIXELS = 1000000000      
# img_file:图片的路径
# path_save:保存路径
# width:宽度
# height:长度
def img_resize(img_file, path_save, width,height):
    img = Image.open(img_file).convert('RGB')
    new_image = img.resize((width,height),Image.ANTIALIAS)
    output_file_path = os.path.join(path_save,os.path.basename(img_file))
    output_file_path=unicode(output_file_path,'utf-8')
    new_image.save(output_file_path)
    
    



input_path = '/328*328'
output_path = '/resize_1024*1024/'

if not os.path.exists(output_path):
    os.makedirs(output_path)

os.system("rm "+output_path)
file_list = os.listdir(input_path)
for index,file_name in enumerate(file_list):
    file_path = os.path.join(input_path,file_name)
    if re.findall(".jpg",file_path):
        img_resize(file_path,output_path,1024,1024)
上一篇 下一篇

猜你喜欢

热点阅读