我是靠谱客的博主 沉默曲奇,这篇文章主要介绍Python批量按比例缩小图片脚本分享,现在分享给大家,希望可以做个参考。

图片太大了,上百张图用photoshop改太慢,就想到用python写个简单的批处理。功能简单就是把原图按比例缩小

复制代码 代码如下:

# -*- coding: cp936 -*- 

import Image 
import glob, os 

#图片批处理 
def timage(): 
    for files in glob.glob('D:\\\\1\\\\*.JPG'): 
        filepath,filename = os.path.split(files) 
        filterame,exts = os.path.splitext(filename) 
        #输出路径 
        opfile = r'D:\\\\22\\\\'
        #判断opfile是否存在,不存在则创建 
        if (os.path.isdir(opfile)==False): 
            os.mkdir(opfile) 
        im = Image.open(files) 
        w,h = im.size 
        #im_ss = im.resize((400,400)) 
        #im_ss = im.convert('P') 
        im_ss = im.resize((int(w*0.12), int(h*0.12))) 
        im_ss.save(opfile+filterame+'.jpg') 

if __name__=='__main__': 
    timage() 

    print '哈哈完蛋啦'

最后

以上就是沉默曲奇最近收集整理的关于Python批量按比例缩小图片脚本分享的全部内容,更多相关Python批量按比例缩小图片脚本分享内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(137)

评论列表共有 0 条评论

立即
投稿
返回
顶部