Skip to content

Instantly share code, notes, and snippets.

@davidroettger
Forked from thobbs/strip_border.py
Created March 23, 2019 14:03
Show Gist options
  • Save davidroettger/5b3bcd444cc54a8f29e5f1f24cc5a14e to your computer and use it in GitHub Desktop.
Save davidroettger/5b3bcd444cc54a8f29e5f1f24cc5a14e 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