Python批量按比例缩小图片脚本分享

yipeiwu_com6年前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使用post及get方式提交数据的实例

最近在使用Python的过程中,发现网上很少提到在使用post方式时,怎么传一个数组作为参数的示例,此处根据自己的实践经验,给出相关示例: 单纯的post请求: def http_p...

Python中datetime模块参考手册

前言 Python提供了多个内置模块用于操作日期时间,像 calendar,time,datetime。time模块提供的接口与C标准库 time.h 基本一致。相比于 time 模块,...

Python3用tkinter和PIL实现看图工具

Python3用tkinter和PIL实现看图工具

需求 想做看图工具的,必然要支持jpg、png等常见格式,但tkinter是个纯粹的GUI库,不像GTK、QT那样大而全,所以只支持gif和ppm两种格式,局限很大,必须搭配图像处理库,...

利用python获取某年中每个月的第一天和最后一天

搜索关键字: python get every first day of month 参考解答: 方法一: >>> import calendar >>...

python2.7 mayavi 安装图文教程(推荐)

python2.7 mayavi 安装图文教程(推荐)

工具:python2.7 相关包:traits-4.6.0-cp27-cp27m-win32.whl, VTK-7.1.1-cp27-cp27m-win32.whl, mayavi-4....