Python 批量生成缩略图

import os, glob
import Image
import fnmatch

ext1 = '10001.jpg'
path = 'E:\\work\\audi'

imgslist = []
for root, dirnames, filenames in os.walk(path):
  for filename in fnmatch.filter(filenames, ext1):
      imgslist.append(os.path.join(root, filename))

width = int(raw_input("the width U want:"))
format = 'jpg'
def small_img():
	for imgs in imgslist:
		imgspath, ext = os.path.splitext(imgs)
		img = Image.open(imgs)
		(x,y) = img.size
		height =int( y * width /x)
		small_img =img.resize((width,height),Image.ANTIALIAS)
		small_img.save(imgspath +".thumbnail."+format)
	print "done"

if __name__ == '__main__':
	small_img()

  

posted @ 2013-03-29 23:02  21天后  阅读(503)  评论(0编辑  收藏  举报
21