wcs/wcs/qommon/static/images/categories/generate.py

51 lines
1.5 KiB
Python

#! /usr/bin/env python
from optparse import OptionParser
import subprocess
import tempfile
import xml.etree.ElementTree as ET
mapping = {
'207': 'trash',
'1673': 'businessperson',
'4335': 'sanitation',
'6412': 'mobile-alarm',
'10860': 'triathlon',
'12513': 'email',
'12581': 'park',
'13644': 'culture',
'14004': 'document',
'14292': 'polling-place',
'23557': 'crosswalk',
'32231': 'document',
'38588': 'shopping-cart',
'39826': 'people',
'39567': 'tools',
'49638': 'event',
'58303': 'placeholder',
'62444': 'fireworks',
}
parser = OptionParser()
parser.add_option('-c', '--colour', dest='colour', metavar='COLOUR')
(options, args) = parser.parse_args()
for icon_id, icon_name in mapping.items():
svg_path = 'src/icon_%s/icon_%s.svg' % (icon_id, icon_id)
if options.colour:
tree = ET.fromstring(file(svg_path).read().replace('#000000', '#%s' % options.colour))
for elem in tree.findall('*'):
if not elem.attrib.get('style'):
elem.attrib['style'] = 'fill:#%s' % options.colour
f = tempfile.NamedTemporaryFile(suffix='.svg', delete=False)
f.write(ET.tostring(tree))
f.close()
svg_path = f.name
output_filename = 'icon_%s_%s_%s.png' % (icon_name, icon_id, options.colour)
else:
output_filename = 'icon_%s_%s.png' % (icon_name, icon_id)
subprocess.call(['inkscape', '--without-gui',
'--file', svg_path,
'--export-png', output_filename,
'--export-width', '42'])