File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ from pathlib import Path
2
+ from PIL import Image
3
+
4
+ # The logos are constrained in CSS to 160 px by 80 px. We allow up to double
5
+ # that size, as high-resolution displays may display more than one pixel in a
6
+ # CSS pixel.
7
+ MAX_WIDTH = 160 * 2
8
+ MAX_HEIGHT = 80 * 2
9
+
10
+ ASSETS_DIR = Path (__file__ ).parent / 'assets'
11
+
12
+ for filename in ASSETS_DIR .glob ('*.png' ):
13
+ im = Image .open (filename )
14
+ w , h = im .size
15
+ if w <= MAX_WIDTH and h <= MAX_HEIGHT :
16
+ # This image is already small enough
17
+ continue
18
+
19
+ # It should fit in both dimensions, so take the smaller scale from them.
20
+ w_scale = MAX_WIDTH / w
21
+ h_scale = MAX_HEIGHT / h
22
+ scale = min (w_scale , h_scale )
23
+
24
+ new_w = int (w * scale )
25
+ new_h = int (h * scale )
26
+
27
+ print (f"Resizing { filename } from { w } ×{ h } to { new_w } ×{ new_h } ." )
28
+
29
+ im .resize ((new_w , new_h )).save (filename )
You can’t perform that action at this time.
0 commit comments