-
Notifications
You must be signed in to change notification settings - Fork 0
/
memberImageCompressor.py
34 lines (29 loc) · 1 KB
/
memberImageCompressor.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
33
34
from PIL import Image
import PIL
import sys, os
import shutil
from pathlib import Path
def copyAndCompress(fromDirectory, compressDirectory):
shutil.rmtree(compressDirectory)
print(fromDirectory)
shutil.copytree(fromDirectory, compressDirectory)
print(compressDirectory)
print(os)
print(os.chdir(compressDirectory))
os.chdir(compressDirectory)
images = [file for file in os.listdir() if file.endswith(('jpg', 'png' ))]
print( images)
print(os.listdir())
for image in images:
# 1. Open the image
img = Image.open(image)
img.thumbnail((128,128), Image.ANTIALIAS)
# 2. Compressing the image
img.save(image,
optimize=True,
quality=100)
base_path = Path(__file__).parent
print("test")
fromDirectory = (base_path / "membersImagesBeforeCompress/membros").resolve()
compressDirectory = (base_path / "membersImagesAfterCompress/membros").resolve()
copyAndCompress(fromDirectory, compressDirectory)