-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathshrink_logos.py
More file actions
29 lines (22 loc) · 844 Bytes
/
shrink_logos.py
File metadata and controls
29 lines (22 loc) · 844 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
28
29
from pathlib import Path
from PIL import Image
# The logos are constrained in CSS to 160 px by 80 px. We allow up to double
# that size, as high-resolution displays may display more than one pixel in a
# CSS pixel.
MAX_WIDTH = 160 * 2
MAX_HEIGHT = 80 * 2
ASSETS_DIR = Path(__file__).parent / 'assets'
for filename in ASSETS_DIR.glob('*.png'):
im = Image.open(filename)
w, h = im.size
if w <= MAX_WIDTH and h <= MAX_HEIGHT:
# This image is already small enough
continue
# It should fit in both dimensions, so take the smaller scale from them.
w_scale = MAX_WIDTH / w
h_scale = MAX_HEIGHT / h
scale = min(w_scale, h_scale)
new_w = int(w * scale)
new_h = int(h * scale)
print(f"Resizing {filename} from {w}×{h} to {new_w}×{new_h}.")
im.resize((new_w, new_h)).save(filename)