zoukankan      html  css  js  c++  java
  • 批量对图片进行缩放

    1.直接上代码,就是对某文件夹下的图片进行批量缩放

    #!python
    import os,sys
    import plistlib
    from PIL import Image
    
    scale_param = 0.852
    root_save_path = 'c:/scale'
    
    def scale_png(path, file, save_path):
        png_path = path + '/' + file
        big_image = Image.open(png_path)
        img_size = big_image.size
        scale_size = [img_size[0] * scale_param, img_size[1] * scale_param]
        # print(scale_param, img_size, scale_size)
        big_image.thumbnail(scale_size, Image.ANTIALIAS)
        big_image.save(save_path + '/' + file)
            
        
    def list_file(path, save_path):
        for file in os.listdir(path):
            if os.path.isdir(path + '/' + file):
                save_path = save_path + '/' + file
                if not os.path.exists(save_path) :
                    os.mkdir(save_path)
                list_file(path + '/' + file, save_path)
                continue
            file_names = os.path.splitext(file)
            print file_names
            if file_names[1] == '.png' or file_names[1] == '.jpg' :
                scale_png(path, file, save_path )
    
    if __name__ == '__main__':
        path = sys.argv[1]
        root_save_path = sys.argv[2]
        scale_param = float(sys.argv[3])
        if not os.path.exists(root_save_path):
            os.mkdir(root_save_path)
    
        if os.path.exists(path) :
            list_file( path, root_save_path )
        else :
            print('please input correct path')
    
    
  • 相关阅读:
    mobileSelect学习
    使用qrcode生成二维码
    点点点右边有内容
    搜索框search
    input样式和修改
    art-template模板引擎高级使用
    Nodejs中的路径问题
    异步编程(回调函数,promise)
    在nodejs中操作数据库(MongoDB和MySQL为例)
    MongoDB数据库
  • 原文地址:https://www.cnblogs.com/zjzyh/p/7421453.html
Copyright © 2011-2022 走看看