#!/usr/local/bin/python
#coding=utf-8

"""
第 0005 题：你有一个目录，装了很多照片，把它们的尺寸变成都不大于 iPhone5 分辨率的大小。
"""

from PIL import Image

iPhone5_WIDTH = 1136
iPhone5_HEIGHT = 640

def resize_iPhone5_pic(path, width=iPhone5_WIDTH, height=iPhone5_HEIGHT, new_path='new.jpg'):
    im = Image.open(path)
    im_resized = im.resize((width,height), Image.ANTIALIAS)
    im_resized.save(new_path)

if __name__ == '__main__':
    resize_iPhone5_pic('0.jpg')
@@ -92,16 +92,25 @@
 %E5%A4%A7%E5%B0%8F%E3%80%82%0A%22%22%22%0A
+import os
 %0Afrom PI
@@ -196,16 +196,26 @@
 ic(path,
+ new_path,
  width=i
@@ -253,28 +253,8 @@
 IGHT
-, new_path='new.jpg'
 ):%0A 
@@ -373,62 +373,365 @@
 h)%0A%0A
-if __name__ == '__main__':%0A    resize_iPhone5_pic('0.jpg
+%0Adef walk_dir(path):%0A    for root, dirs, files in os.walk(path):%0A        for f_name in files:%0A            if f_name.lower().endswith('jpg'):%0A                path_dst = os.path.join(root,f_name)%0A                f_new_name = 'iPhone5_' + f_name%0A                resize_iPhone5_pic(path=path_dst, new_path=f_new_name)%0A%0Aif __name__ == '__main__':%0A    walk_dir('./
 ')
+%0A

fix 0005