Python批量按比例缩小图片脚本分享,
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 '哈哈完蛋啦'
相关内容
- Linux下用Python脚本监控目录变化代码分享,linuxpython
- Python检测字符串中是否包含某字符集合中的字符,pyt
- Python中字典的基本知识初步介绍,python字典知识
- 详解Python中的type()方法的使用,pythontype
- 在Python中操作字典之clear()方法的使用,pythonclear
- 浅谈Python中copy()方法的使用,pythoncopy
- 在Python中操作字典之fromkeys()方法的使用,pythonfromkeys
- 在Python中用get()方法获取字典键值的教程,pythonget
- 在Python中用has_key()方法查找键是否存在的教程,python
- Python中使用items()方法返回字典元素对的教程,pythonit
评论关闭