python使用PIL压缩图片


import Image
import os
import os.path
import sys
path = sys.argv[1]
small_path = (path[:-1] if path[-1]=='/' else path) +'_small'
if not os.path.exists(small_path):
    os.mkdir(small_path)
for root, dirs, files in os.walk(path):
    for f in files:
        fp = os.path.join(root, f)
        img = Image.open(fp)
        w, h = img.size
        img.resize((w/2, h/2)).save(os.path.join(small_path, f), "JPEG")
        print fp

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM