pytho修改图片大小

先通过 http://www.pythonware.com/products/pil/    下载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


原文地址
pytho修改图片大小 http://www.bcwhy.com/thread-21130-1-1.html

你可能感兴趣的:(pytho修改图片大小)