less copy protection, more size visualization
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

25 line
711 B

  1. import sys
  2. import re
  3. from xml.etree import ElementTree
  4. from pathlib import Path
  5. for path in Path(sys.argv[1]).rglob('*.svg'):
  6. tree = ElementTree.ElementTree()
  7. parsed = tree.parse(path)
  8. if "width" not in parsed.attrib:
  9. print(f"Rewriting {path}")
  10. width, height = parsed.attrib["viewBox"].split(" ")[-2:]
  11. # I'd rather avoid mangling the XML files by parsing them first
  12. # XML is awful and we never should have invented it :(
  13. with open(path, "r") as file:
  14. data = file.read()
  15. data = re.sub('viewBox="0 0', f'width="{width}" height="{height}" viewBox="0 0', data)
  16. with open(path, "w") as file:
  17. file.write(data)