File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments