#!/usr/bin/env python
# $Id: thumbnails_create.py 5 2007-05-10 05:44:05Z zhuzhu $
# first you must install Python Imaging Library (PIL) at
# http://www.pythonware.com/products/pil/
import os, sys
import Image
import glob
size = [580,1024]
files = glob.glob('*.jpg')
# files = ["Leah_Dizon_613516.jpg"]
for infile in files:
im = Image.open(infile)
if im.size[0] > size[0]:
how = (size[0]*100)/im.size[0]
outfile = os.path.splitext(infile)[0] + ".webcan.jpg"
if infile != outfile:
try:
im = im.resize((size[0], (im.size[1]*how)/100), Image.BILINEAR)
im.save(outfile, "JPEG")
print outfile+" is created"
except IOError:
print "cannot create thumbnail for", infile
else:
print "not need create thumbnail for", infile
我还收集了一个python的小小手册,相当于是FAQ吧。
No comments:
Post a Comment