Skip to content

Instantly share code, notes, and snippets.

@thobbs
Created August 28, 2018 05:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thobbs/1b5aa991f03d55e2488df7ad8799f8f8 to your computer and use it in GitHub Desktop.
Save thobbs/1b5aa991f03d55e2488df7ad8799f8f8 to your computer and use it in GitHub Desktop.
Strip the border from an SVG for plotting through Inkscape
import sys
import lxml.etree as le
def main(filename):
with open(filename, 'r+b') as f:
doc = le.parse(f)
# strip border strokes
for elem in doc.xpath('//*[attribute::style]'):
if 'stroke:none' in elem.attrib['style']:
parent = elem.getparent()
parent.remove(elem)
# convert dimensions to inches
root = doc.getroot()
width = int(root.attrib['width'])
height = int(root.attrib['height'])
root.attrib['width'] = str(width / 90.0) + "in"
root.attrib['height'] = str(height / 90.0) + "in"
f.seek(0)
doc.write(f, pretty_print=True)
f.truncate()
if __name__ == '__main__':
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment