#!/usr/bin/python # -*- coding: iso-8859-1 -*- # Python Imports import os import sys import subprocess def usage(): print """Usage: %s border inkscape-export-options file.svg Export with inkscape use --export-area-drawing but add a border. Example: %s 20 -e file.png file.svg """ % ( os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0])) def main(): if len(sys.argv)<5: usage() sys.exit() border=int(sys.argv[1]) svgfile=sys.argv[-1] assert os.path.exists(svgfile) floats=[] for item in ["x", "y", "width", "height"]: p=subprocess.Popen(["inkscape", "--query-%s" % item, "--without-gui", svgfile], stdout=subprocess.PIPE) floats.append(float(p.stdout.read())) #area="%.4f:%.4f:%.4f:%.4f" % ( area="%.0f:%.0f:%.0f:%.0f" % ( floats[0]-border, floats[1]-border, floats[0]+floats[2]+border, floats[1]+floats[3]+border) print floats print area cmd=["inkscape", "--without-gui", "--export-area=%s" % area] cmd.extend(sys.argv[2:]) p=subprocess.Popen(cmd) sys.exit(p.wait()) if __name__=="__main__": main()