zulip/static/assets/favicon/generate

25 lines
788 B
Python
Executable File

#!/usr/bin/env python3
import subprocess
from xml.etree import ElementTree as ET
# Generates the favicon images containing unread message counts.
# Open the SVG and find the number text elements using XPath
tree = ET.parse('orig.svg')
elems = [tree.getroot().findall(
f".//*[@id='{name}']/{{http://www.w3.org/2000/svg}}tspan")[0]
for name in ('number_back', 'number_front')]
for i in range(1, 100):
# Prepare a modified SVG
s = f'{i:2}'
for e in elems:
e.text = s
with open('tmp.svg', 'wb') as out:
tree.write(out)
# Convert to PNG
subprocess.check_call(['inkscape', '--without-gui', '--export-area-page',
f'--export-png=../../../static/images/favicon/favicon-{i}.png',
'tmp.svg'])