1
1
import fnmatch
2
2
import os
3
3
4
- # sudo pip install Wand
4
+ # pip install Wand
5
5
from wand .image import Image
6
- # sudo pip install http://pypi.python.org/packages/source/h/hurry.filesize/hurry.filesize-0.9.tar.gz
6
+ # pip install http://pypi.python.org/packages/source/h/hurry.filesize/hurry.filesize-0.9.tar.gz
7
7
from hurry .filesize import size
8
8
9
9
@@ -19,12 +19,13 @@ def get_image_file_names(filepath, pattern):
19
19
for filename in fnmatch .filter (filenames , pattern ):
20
20
matches .append (os .path .join (root , filename )) # full path
21
21
if matches :
22
- print "Found {} files, with a total file size of {}." .format (len (matches ), get_total_size (matches ))
22
+ print ("Found {} files, with a total file size of {}." .format (
23
+ len (matches ), get_total_size (matches )))
23
24
return matches
24
25
else :
25
- print "No files found."
26
+ print ( "No files found." )
26
27
else :
27
- print "Sorry that path does not exist. Try again."
28
+ print ( "Sorry that path does not exist. Try again." )
28
29
29
30
30
31
def get_total_size (list_of_image_names ):
@@ -35,15 +36,15 @@ def get_total_size(list_of_image_names):
35
36
36
37
37
38
def resize_images (list_of_image_names ):
38
- print "Optimizing ... "
39
+ print ( "Optimizing ... " )
39
40
for index , image_name in enumerate (list_of_image_names ):
40
41
with open (image_name ) as f :
41
42
image_binary = f .read ()
42
43
with Image (blob = image_binary ) as img :
43
44
if img .height >= 600 :
44
45
img .transform (resize = 'x600' )
45
46
img .save (filename = image_name )
46
- print "Optimization complete."
47
+ print ( "Optimization complete." )
47
48
48
49
49
50
if __name__ == '__main__' :
0 commit comments