-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_resize_multithread.py
More file actions
38 lines (28 loc) · 1.07 KB
/
Copy pathimage_resize_multithread.py
File metadata and controls
38 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from PIL import Image
import os
import glob
import PySimpleGUI as sg
count = 0
layout = [[sg.Text('Source '), sg.InputText(), sg.FolderBrowse()],
[sg.Text('Destination'), sg.InputText(), sg.FolderBrowse()],
[sg.Text('X'), sg.InputText(size=(25, 1)), sg.Text('Y'), sg.InputText(size=(25, 3))],
[sg.Ok()]]
window = sg.Window('Image Resizer').Layout(layout)
event, values = window.Read()
total_files = len(glob.glob(values[0] + '/*.*'))
source = values[1]
print(total_files)
print(values[2])
def resize(location):
try:
img_orig = Image.open(location)
img_mod = img_orig.resize(tuple([int(values[2]), int(values[3])]), Image.LANCZOS)
file_list = location.split('.')
x = len(file_list) - 1
img_mod.save(str(source) + '/{}.'.format(count) + str(file_list[x]))
except:
print("Error " + filepath)
for filepath in glob.iglob(values[0] + '/*.*'):
sg.OneLineProgressMeter('Resizing', count, total_files, 'key')
count = count + 1
resize(filepath)