export.py (3766B)
1 #!/usr/bin/env python3 2 # the flat logo into every png the repo ships, plus the banner. STYLE=glass for the 0.7 one 3 import gi, os, importlib.util, subprocess 4 gi.require_version('Rsvg', '2.0') 5 from gi.repository import Rsvg 6 import cairo 7 from PIL import Image, ImageFont, ImageDraw, ImageChops 8 9 HERE = os.path.dirname(os.path.abspath(__file__)) 10 REPO = os.path.join(HERE, '..', '..') 11 spec = importlib.util.spec_from_file_location('m', os.path.join(HERE, 'make.py')) 12 m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m) 13 STYLE = os.environ.get('STYLE', 'flat') 14 15 # icons: tight box, a shadow only where there is room for one 16 def svgtext(n): 17 s = m.svg(STYLE, n, 'g') 18 if STYLE == 'flat': 19 # no shadow to make room for: the same margin all round, like the first logo.png 20 return s.replace('viewBox="-16 -16 544 560"', 'viewBox="-6 -6 524 524"') 21 if n <= 32: 22 s = s.replace(' filter="url(#gdrop)"', '').replace('viewBox="-16 -16 544 560"', 'viewBox="-4 -4 520 520"') 23 else: 24 s = s.replace('viewBox="-16 -16 544 560"', 'viewBox="-12 -8 536 544"') 25 return s 26 27 def png(n, out=None): 28 h = Rsvg.Handle.new_from_data(svgtext(n).encode()) 29 s = cairo.ImageSurface(cairo.FORMAT_ARGB32, n, n) 30 v = Rsvg.Rectangle(); v.x = v.y = 0; v.width = v.height = n 31 h.render_document(cairo.Context(s), v) 32 p = os.path.join(HERE, 'out', '%d.png' % n) 33 s.write_to_png(p) 34 im = Image.open(p).convert('RGBA') 35 if out: 36 im.save(out) 37 return im 38 39 def font(name, sz): 40 path = subprocess.run(['fc-match', '-f', '%{file}', name], capture_output=True, text=True).stdout 41 return ImageFont.truetype(path, sz) 42 43 # ring, then "Chamesle" in bold serif and LINUX spaced out under it, black on nothing 44 def banner(scale=2): 45 ring = png(116 * scale) 46 big, sub = font('Liberation Serif:bold', 76 * scale), font('Liberation Sans:bold', 20 * scale) 47 word = 'Chamesle' 48 bb = big.getbbox(word) 49 tw, th = bb[2], bb[3] 50 gap = 22 * scale 51 W = ring.width + gap + tw + 8 * scale 52 ty = int(ring.height * .1) 53 H = max(ring.height, ty + th + int(sub.size * 1.6)) 54 out = Image.new('RGBA', (W, H)) 55 out.alpha_composite(ring, (0, (H - ring.height) // 2)) 56 tx = ring.width + gap 57 d = ImageDraw.Draw(out) 58 d.text((tx, ty), word, font=big, fill=(0, 0, 0, 255)) 59 x = tx + 4 * scale 60 for ch in 'LINUX': 61 d.text((x, ty + th + 4 * scale), ch, font=sub, fill=(0, 0, 0, 255)) 62 x += sub.getlength(ch) + 9 * scale 63 return out 64 65 if __name__ == '__main__': 66 os.makedirs(os.path.join(HERE, 'out'), exist_ok=True) 67 open(os.path.join(REPO, 'artwork', 'logo.svg'), 'w').write(m.svg(STYLE, 512, 'g')) 68 for n in (16, 22, 24, 32, 48, 64, 128, 256): 69 for d in ('overlay/usr/share/icons/hicolor/%dx%d/apps/chamesle-start.png', 70 'tools/pkg/chamesle-kde/files/usr/share/icons/hicolor/%dx%d/apps/chamesle-start.png', 71 'tools/pkg/chamesle-artwork/files/usr/share/icons/Chamesle/%dx%d/places/start-here.png'): 72 p = os.path.join(REPO, d % (n, n)) 73 if os.path.exists(p): 74 png(n, p) 75 for p in ('artwork/logo.png', 'docs/img/logo.png', 'overlay/usr/share/live-installer/logo.png', 76 'overlay/usr/share/live-installer/slideshow/logo.png'): 77 png(524, os.path.join(REPO, p)) 78 png(168, os.path.join(REPO, 'tools/pkg/chamesle-plymouth/files/usr/share/plymouth/themes/chamesle/logo.png')) 79 big = Image.new('RGB', (2000, 2000), 'white'); big.paste(i := png(2000), mask=i) 80 big.save(os.path.join(REPO, 'artwork/logo.jpeg'), quality=92) 81 # greeter: dark screen, so new ring and the old white word 82 g = Image.open(os.path.join(HERE, 'greeter-word.png')).convert('RGBA') 83 g.paste((0, 0, 0, 0), (0, 0, 73, 80)) 84 g.alpha_composite(png(72), (0, 4)) 85 g.save(os.path.join(REPO, 'tools/pkg/chamesle-artwork/files/usr/share/chamesle/greeter-logo.png')) 86 b = banner() 87 b.save(os.path.join(REPO, 'artwork/banner.png')) 88 print('logo out', b.size)