-
-
Save miguelbermudez/3801411 to your computer and use it in GitHub Desktop.
Extract SVG paths and convert to JSON for use with Raphael.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.dom import minidom | |
import json | |
config = { | |
'svg_file' : 'map.svg', | |
'js_file' : 'map.js', | |
'js_var' : 'svgMap' | |
} | |
svg = minidom.parse(config['svg_file']) | |
paths = svg.getElementsByTagName('path') | |
items = {} | |
for node in paths: | |
if node.getAttributeNode('id'): | |
path_id = str(node.getAttributeNode('id').nodeValue) | |
path = str(node.getAttributeNode('d').nodeValue) | |
items[path_id] = path | |
json = json.dumps(items, indent=2) | |
f = open(config['js_file'], 'w') | |
f.write('var %s = ' % config['js_var']) | |
f.write(json) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment