Created
August 28, 2018 05:46
-
-
Save thobbs/1b5aa991f03d55e2488df7ad8799f8f8 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