5
5
# https://github.com/dn0z/Batch-Image-Resize
6
6
7
7
import os
8
- from PIL import Image
8
+ import PIL . Image
9
9
from tkinter import *
10
10
from tkinter import ttk
11
11
from tkinter import filedialog
@@ -68,7 +68,7 @@ def get_filename_with_type(self, filename, file_type, suffix=""):
68
68
"""
69
69
70
70
extension = filename .split ("." )[- 1 ]
71
- return filename [:- len (extension )] + suffix + "." + file_type .lowercase ()
71
+ return filename [:- ( len (extension ) + 1 ) ] + suffix + "." + file_type .lower ()
72
72
73
73
def export_file (self , path , name , width , height , export_type , overwrite ):
74
74
"""
@@ -85,17 +85,16 @@ def export_file(self, path, name, width, height, export_type, overwrite):
85
85
img_path = os .path .join (path , name )
86
86
87
87
# open the given image and resize it
88
- img = Image .open (img_path )
89
- img = img .resize ((width , height ), Image .ANTIALIAS )
88
+ img = PIL . Image .open (img_path )
89
+ img = img .resize ((width , height ), PIL . Image .ANTIALIAS )
90
90
91
91
# set the destination image file we want to save
92
92
dest_img_name = self .get_filename_with_type (name , export_type , "_resized" )
93
93
if overwrite :
94
94
dest_img_name = name
95
95
96
96
# save the resized/converted image
97
- print ("Save to " + os .path .join (path , dest_img_name ))
98
- # img.save(os.path.join(path, dest_img_name))
97
+ img .save (os .path .join (path , dest_img_name ))
99
98
100
99
def init_export (self ):
101
100
"""
@@ -117,6 +116,7 @@ def init_export(self):
117
116
for path , subdirs , files in os .walk (directory_path ):
118
117
for name in files :
119
118
if self .is_image (name ):
119
+ # TODO: Add a new window with a progress bar while exporting images
120
120
self .export_file (path , name , width , height , export_type , overwrite )
121
121
122
122
# at this point, we are done with our exports, display a success message
0 commit comments