08/02/27 03:31:35
>>594
うーん、あんま変わんなかったような。まぁ練習ということで。
import re, os, Image
dirname = u'.'
exts = ('.jpg', '.gif', '.png', '.bmp')
suffix = u'-thumb'
for fn in os.listdir(dirname):
filename = os.path.join(dirname, fn)
basename, ext = os.path.splitext(fn)
if ext.lower() in exts \
and os.path.isfile(filename) \
and not basename.endswith(suffix):
r = Image.open(filename)
r.thumbnail((200,200), Image.ANTIALIAS)
newfile = os.path.join(dirname, basename + suffix + ext)
print fn, '->', newfile
r.save(newfile)