figure resize

作者: 狼无雨雪 | 来源:发表于2019-07-15 14:06 被阅读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)
    

    相关文章

      网友评论

        本文标题:figure resize

        本文链接:https://www.haomeiwen.com/subject/ftxdhctx.html