Python批量按比例缩小图片脚本分享
作者:junjie 时间:2022-06-06 11:46:12
图片太大了,上百张图用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,批量,按比例,缩小,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python文件写入write()的操作
2023-11-10 04:33:11
快速解决Django关闭Debug模式无法加载media图片与static静态文件
2023-05-28 02:54:43
儿童编程python入门
2021-03-12 15:25:06
![](https://img.aspxhome.com/file/2023/5/79645_0s.jpg)
使用XML技术上传文件的例子
2008-05-29 11:33:00
Python基于Logistic回归建模计算某银行在降低贷款拖欠率的数据示例
2023-11-27 21:26:53
![](https://img.aspxhome.com/file/2023/8/70208_0s.png)
做了CDN加速的ASP网站获取用户真实IP程序
2011-02-16 10:59:00
css基础教程之序曲
2008-07-23 12:40:00
用ASP实现IE地址栏参数的判断
2008-10-10 15:54:00
基于Python编写简单实用的日志装饰器
2022-10-09 01:21:51
![](https://img.aspxhome.com/file/2023/3/75213_0s.png)
python基础之引用和匿名函数
2023-01-13 11:52:42
![](https://img.aspxhome.com/file/2023/3/81563_0s.jpg)
Pytest mark使用实例及原理解析
2021-02-27 14:30:11
asp下用fso和ado.stream写xml文件的方法
2011-04-07 10:55:00
python 装饰器重要在哪
2023-12-30 12:13:29
[译]JavaScript中的Timer是怎么工作的
2009-02-06 15:39:00
![](https://img.aspxhome.com/file/UploadPic/20092/6/timers-65s.png)
php fopen()函数案例详解
2023-07-16 22:21:26
40个网页设计常用小代码
2008-01-01 19:27:00
asp添加数据实现代码
2011-02-05 10:42:00
利用python解决mysql视图导入导出依赖的问题
2023-10-28 07:27:38
PHP排序二叉树基本功能实现方法示例
2023-07-10 04:45:53
在pytorch中计算准确率,召回率和F1值的操作
2022-02-13 18:06:40
![](https://img.aspxhome.com/file/2023/8/76778_0s.png)