Skip to content

Commit 94d6cfd

Browse files
committed
Create 0005.py
1 parent 3c8e48b commit 94d6cfd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

razzl/0005/0005.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
It can resize the photos in a file
3+
'''
4+
5+
import os
6+
from PIL import Image
7+
8+
def resize_photo(source_dir,width,higth,destination_dir):
9+
photos = os.listdir(source_dir)
10+
for photo in photos:
11+
photo_abspath = os.path.join(source_dir,photo)#if you use os.path.abspath,there may be some error
12+
print photo_abspath
13+
if(os.path.isfile(photo_abspath)):#os.path.isfile need a abspath
14+
im = Image.open(photo_abspath)
15+
#w,h = im.size
16+
new_im = im.resize((width,higth))#note: the resize returns a resized copy of an image , so you need a new object to save it
17+
destination_path = os.path.join(destination_dir,photo)
18+
new_im.save(destination_path)
19+
print destination_path
20+
resize_photo('C:/Users/razzl/Desktop/1',800,800,'C:/Users/razzl/Desktop/2')
21+
22+

0 commit comments

Comments
 (0)