-
-
Save davidroettger/5b3bcd444cc54a8f29e5f1f24cc5a14e to your computer and use it in GitHub Desktop.
Strip the border from an SVG for plotting through Inkscape
This file contains hidden or 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
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