r500/resize_svg.py
2025-10-23 13:27:37 -05:00

23 lines
787 B
Python

import sys
scale = 1.5
def transform():
with open(sys.argv[1]) as f:
for line in f.readlines():
if line.strip().startswith("<svg xmlns"):
width = line.split('width="')[1].split('"')[0]
height = line.split('height="')[1].split('"')[0]
viewbox = line.split('viewBox="')[1].split('"')[0]
width = float(width) * scale
height = float(height) * scale
template = f'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{width}" height="{height}" viewBox="{viewbox}">'
yield template
else:
yield line
lines = list(transform())
with open(sys.argv[1], 'w') as f:
f.write('\n'.join(lines))