-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconverter.py
32 lines (29 loc) · 913 Bytes
/
converter.py
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
import os
from threading import Thread
from PIL import Image
d = "/home/malyhass/log-parser/image"
output = os.path.join(d, "smaller")
filenames = os.listdir(d)
class ImageConverter(Thread):
def run(self):
while True:
try :
filename = filenames.pop()
except IndexError:
break
if not filename.lower().endswith("jpg"):
continue
print self.getName(), "is processing", filename
im = Image.open(os.path.join(d, filename))
width, height = im.size
smaller = im.resize((400, height * 800 / width))
smaller.save(os.path.join(output, filename))
if not os.path.exists(output):
os.makedirs(output)
threads = []
for i in range (0, 2):
threads.append(ImageConverter())
for thread in threads:
thread.start()
for thread in threads:
thread.join()