-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress.py
More file actions
27 lines (20 loc) · 731 Bytes
/
compress.py
File metadata and controls
27 lines (20 loc) · 731 Bytes
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
from io import BytesIO
from PIL import Image
Image.MAX_IMAGE_PIXELS = None
counter = 0
import os
for root, dirs, files in os.walk("../cse3000-research-project.github.io/content/posters", topdown=False):
for name in files:
if "poster" in name and "pdf" not in name and "PDF" not in name:
counter += 1
print(counter)
pth = os.path.join(root, name)
img = Image.open(pth)
buffer = BytesIO()
try:
img.save(buffer, "JPEG", quality=5)
print(pth)
with open(pth, "wb") as handle:
handle.write(buffer.getbuffer())
except:
pass