Created
January 20, 2015 16:10
-
-
Save sneetsher/19bbfdb60788f302025a to your computer and use it in GitHub Desktop.
SVG is an XML, you can use this python script to generate slices. Actually, it does not slice it, but uses same copy of input file with different values of viewBox to show only target area.
This file contains 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
#!/usr/bin/env python | |
""" | |
Generate slices | |
python svg_slice.py 2 1 askUbuntu.svg | |
ie: 2x1 grid | |
Then use Inkscape to export PDF for each slice/cell | |
for i in $(ls cell_*); do inkscape $i --export-pdf=$i.pdf; done; | |
""" | |
import sys, os.path | |
import xml.etree.ElementTree as ET | |
fin=sys.argv[-1] | |
hsplit=int(sys.argv[1]) | |
vsplit=int(sys.argv[2]) | |
tree = ET.parse(fin) | |
root = tree.getroot() | |
hstep=float(root.attrib['width'])/hsplit | |
vstep=float(root.attrib['height'])/vsplit | |
root.attrib['width']=str(hstep) | |
root.attrib['height']=str(vstep) | |
for i in range(hsplit): | |
for j in range(vsplit): | |
root.attrib['viewBox']='%.4f %.4f %.4f %.4f' % (i*hstep, j*vstep, hstep, vstep) | |
tree.write('cell_%i-%i_%s' % (i,j,os.path.basename(fin))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment