buttons.py (2425B)
1 #!/usr/bin/env python3 2 # the little 88x31 buttons at the bottom of the website, drawn a pixel at a time like they were. 3 # python3 artwork/buttons.py -> docs/img/buttons/*.png 4 import os, subprocess 5 from PIL import Image, ImageDraw, ImageFont 6 7 HERE = os.path.dirname(os.path.abspath(__file__)) 8 OUT = os.path.join(HERE, '..', 'docs', 'img', 'buttons') 9 10 def font(name, size): 11 path = subprocess.run(['fc-match', '-f', '%{file}', name], capture_output=True, text=True).stdout 12 return ImageFont.truetype(path, size) 13 14 def button(bg, light, dark): 15 im = Image.new('RGB', (88, 31), bg) 16 d = ImageDraw.Draw(im) 17 d.fontmode = '1' # no smoothing, hard pixels 18 d.rectangle((0, 0, 87, 30), outline='#000') 19 d.line((1, 1, 86, 1), fill=light); d.line((1, 1, 1, 29), fill=light) 20 d.line((1, 29, 86, 29), fill=dark); d.line((86, 1, 86, 29), fill=dark) 21 return im, d 22 23 # a line of text, centred between x0 and the right edge, a size smaller until it fits 24 def text(d, xy, s, f, fill, x0=None): 25 x, y = xy 26 left = x if x0 is None else x0 27 room = 84 - left 28 size = f.size 29 while d.textlength(s, font=f) > room and size > 7: 30 size -= 1 31 f = f.font_variant(size=size) 32 d.text((left + (room - d.textlength(s, font=f)) // 2, y), s, font=f, fill=fill) 33 34 os.makedirs(OUT, exist_ok=True) 35 bold = lambda n: font('Liberation Sans:bold', n) 36 small = lambda n: font('Liberation Sans', n) 37 38 # ours, for anyone who wants to link here 39 im, d = button('#ffffff', '#ffffff', '#808080') 40 ring = Image.open(os.path.join(HERE, 'logo.png')).convert('RGBA').resize((25, 25), Image.LANCZOS) 41 im.paste(ring, (4, 3), ring) 42 text(d, (31, 4), 'CHAMESLE', bold(10), '#000') 43 text(d, (31, 16), 'get it here', small(10), '#0000ee') 44 im.save(os.path.join(OUT, 'chamesle.png')) 45 46 # any browser will do 47 im, d = button('#000080', '#6060ff', '#000030') 48 text(d, (4, 3), 'best viewed with', small(9), '#ffffff') 49 text(d, (4, 14), 'ANY BROWSER', bold(11), '#ffff00') 50 im.save(os.path.join(OUT, 'anybrowser.png')) 51 52 # what it's made from 53 im, d = button('#e8f4ec', '#ffffff', '#5d7d68') 54 text(d, (4, 3), 'built on', small(10), '#000') 55 text(d, (4, 14), 'VOID LINUX', bold(11), '#2f6b46') 56 im.save(os.path.join(OUT, 'void.png')) 57 58 # nothing watching you here 59 im, d = button('#ffffe0', '#ffffff', '#9a9a60') 60 text(d, (4, 3), 'this site has', small(10), '#000') 61 text(d, (4, 14), 'NO TRACKERS', bold(11), '#c00000') 62 im.save(os.path.join(OUT, 'notrackers.png')) 63 print('buttons in', os.path.normpath(OUT))