favicon: Add a script to generate numbered favicons

(imported from commit a80515c97a198eb2effaadcc578eeb4bf4c6b327)
This commit is contained in:
Keegan McAllister 2013-02-15 14:27:15 -05:00
parent cd8353d48e
commit 4499f764e3
2 changed files with 25 additions and 0 deletions

1
assets/favicon/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/tmp.svg

24
assets/favicon/generate Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
import xml.etree.ElementTree as ET
import subprocess
# 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(
".//*[@id='%s']/{http://www.w3.org/2000/svg}tspan" % (name,))[0]
for name in ('number_back', 'number_front')]
for i in xrange(1,100):
# Prepare a modified SVG
s = '%2d' % (i,)
for e in elems:
e.text = s
with open('tmp.svg', 'w') as out:
tree.write(out)
# Convert to PNG
subprocess.check_call(['inkscape', '--without-gui', '--export-area-page',
'--export-png=../../zephyr/static/images/favicon/favicon-%d.png' % (i,),
'tmp.svg'])