Makefile inspired export from SVG files using Inkscape as backend with some added smartness.
If you're tired of clicking "Export Bitmap…" in Inkscape or you want to automate the process of batch exporting bitmaps or other formats from SVG files then inkmake might be something for you.
With inkmake you describe what you want to export and how using a Inkfile
and then inkmake takes care of generating the necessary files.
# this is a Inkfile
# will generate duck.png from duck.svg
duck.png
# will generate a high resolution duck
hiresduck.png duck.svg *10
# will generate files duck.png, [email protected] and duck-right.png from animals.svg using area id @duck
images/duck[@2x|-right=*3,right].png animals.svg @duck
# output files relative to the parent directory of the Inkfile
out: ../
# read SVG files from to the child directory "resources" relative to the Inkfile
svg: resources
Currently inkmake should work on Mac OS X, Linux, BSD variants and with some effort even on Windows.
On Mac OS X you only need to install Inkscape. inkmake is written in Ruby and should work with the default Ruby version included in Mac OS X.
On Linux and BSD variants you need to install Ruby and Inkscape and make sure they are in the shell PATH
.
On Windows you need to install Ruby and Inkscape. You probably also want to rename inkmake
to inkmake.rb
and associate .rb
with Ruby.
As Administrator run this in a cmd
prompt, Ruby install path may be different.
$ assoc .rb=RubyScript
$ ftype RubyScript="c:\Ruby139\bin\ruby.exe" "%1" %*
Homebrew:
$ brew install --HEAD https://raw.github.com/wader/inkmake/master/homebrew/inkmake.rb
Manually:
Easiest usage is probably to download and copy inkmake
to /usr/local/bin
and make sure its executable chmod a+x /usr/local/bin/inkmake
and is in your shell PATH
(Mac OS X how to). You can also copy it somewhere else and use the full path when executing it.
Default inkmake reads a file called "Inkfile" in the current directory and will read and output files relative to the directory containing the Inkfile
. But you can both specify the Inkfile
path as a last argument and also change the SVG source dirctory and output directory using the --svg
and --out
argument options.
Usage: ./inkmake [options] [Inkfile]
-v, --verbose Verbose output
-s, --svg PATH SVG source base path
-o, --out PATH Output base path
-f, --force Force regenerate (skip time check)
-i, --inkscape PATH Inkscape binary path
Default: /Applications/Inkscape.app/Contents/Resources/bin/inkscape
-h, --help Display help
Each line in a Inkfile describe exports to be made from a SVG file. The basic syntax looks like this:
# this is comment
file[variants].ext [options]
Where variants
and options
are optional. So in its simplest form a line look like this:
file.png
And would generate a file called file.png
from the SVG file file.svg
using the default resolution of the SVG file.
options
allow you to specify which part of a SVG to export and at which resolution, it also allow you to specify if the output should be rotated in some way.
duck.png animals.svg @duck *2 right
This would export the area defined by id duck
from the SVG file animals.svg
in double resolution and rotate the image 90 degrees clockwise.
All available options:
path.svg |
Source SVG file. Relative to current SVG source path. |
123x123, 123in*123in |
Set output resolution. Supported units are
px (absolute pixels, default),
pt ,
pc ,
mm ,
cm ,
dm ,
m ,
in ,
ft and
uu (user units, pixels at 90dpi).
|
*2 , *2.5 |
Scale output when using non-pixel units. |
drawing |
Export drawing area (default whole page is exported). |
@id |
Export area defined by id . |
@x0:y0:x1:y1 |
Export specified area. x0:y0 is lower left, x1:y1 is upper right. In user units. |
left , right , upsidedown |
Rotate output image, right means 90 degrees clockwise. |
png , pdf , ps , eps |
Force output format when it can't be determined by the output path. |
180dpi
| Change dots per inch when rendering non-pixel units (default is 90dpi). |
With variants you can export more than one file with different options
. This is usefull if you want to export the same SVG or part of a SVG in different resolution or rotations, and it also saves you some typing as you don't need to repeat the output path.
variants
is a pipe |
separated list of name=options
pairs, where name
is the part of the output path to be used and options
are options specific to the variant. There is also a shortcut syntax for generating iOS scaled images where you only specify @2x
as a variant.
duck[@2x|-right=right|-big=1000x1000].png animals.svg @duck
Would generate the images duck.png
in resolution specified by id duck
, [email protected]
in double resolution, duck-right.png
rotated 90 degrees clockwise and duck-big.png
in 1000x1000 pixels.
All available variant options:
left , right , upsidedown |
Rotate output image, right means 90 degrees clockwise. |
123x123, 123in*123in |
Set output resolution. Supported units are
px (absolute pixels, default),
pt ,
pc ,
mm ,
cm ,
dm ,
m ,
in ,
ft and
uu (user units, pixels at 90dpi).
|
*2 , *2.5 |
Scale output when using non-pixel units. |
180dpi
| Change dots per inch when rendering non-pixel units (default is 90dpi). |
Special variants:
@2x |
Shortcut for @2x=*2 . Usefull when generating iOS scaled images. |
Both SVG base path and output base path can be set from the Inkfile
or with command line arguments. The order of preference is, first command line argument then Inkfile
out:
/svg:
configuration and if non of them is provided the paths fallback to be relative to the Inkfile
.
Resolutions specified in the Inkfile
without units or as px
will always be absolute number of pixels in output image and will not change depending on scale and dpi.
If you don't specify any resolution the resolution and units will depend on how its defined in the SVG file. In the case of SVG files saved by Inkscape this is most likely user units which is defined as pixels at 90dpi which inkmake will translate to absolute depending on scale and dpi if specified.
Plain SVG output? does not work with areas