Skip to content

Commit

Permalink
SVG to PNG conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Oberstein committed Oct 26, 2013
1 parent 0ee944c commit 96bd316
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup (
name = 'taschenmesser',
version = '0.0.1',
version = '0.0.2',
description = 'Taschenmesser, a toolbelt with plugins for SCons',
long_description = LONGSDESC,
license = 'Apache License 2.0',
Expand Down
36 changes: 35 additions & 1 deletion taschenmesser/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


def exists(env):
if not env.Detect("inkscape"):
print "Taschenmesser: Inkscape executable not found - SVG to PNG conversion won't be available."
try:
import scour
return True
Expand All @@ -31,7 +33,10 @@ def exists(env):

def generate(env):
from SCons.Builder import Builder

import scour
import os, subprocess


def Scour(target, source, env):
if len(source) > 1:
Expand Down Expand Up @@ -63,5 +68,34 @@ def Scour(target, source, env):

scour.scour.start(options, instream, outstream)


env.Append(BUILDERS = {'Scour': Builder(action = Scour)})


def Svg2Png(target, source, env):
inkscape = env.Detect("inkscape")

infile = str(source[0])
outfile = str(target[0])

cmd = []
cmd.append(inkscape)
cmd.extend(['-z', '-e', outfile])

if env.has_key('SVG2PNG_OPTIONS'):

if env['SVG2PNG_OPTIONS'].has_key('width'):
width = int(env['SVG2PNG_OPTIONS']['width'])
cmd.extend(['-w', '%d' % width])

if env['SVG2PNG_OPTIONS'].has_key('height'):
height = int(env['SVG2PNG_OPTIONS']['height'])
cmd.extend(['-h', '%d' % height])

cmd.extend([infile])

# "C:\Program Files (x86)\Inkscape\inkscape.exe" -z -e crossbar_hiw_architecture.png -w 1024 crossbar_hiw_architecture.svg

print ' '.join(cmd)
subprocess.call(cmd)

env.Append(BUILDERS = {'Svg2Png': Builder(action = Svg2Png)})

0 comments on commit 96bd316

Please sign in to comment.