Inkscape is a powerful open-source vector graphics editor which supports the inclusion of raster images either through file references (links) or through direct embedding of the image data in the Inkscape SVG file. Referencing images as links keeps SVG files small and ensures that changes to image placement and transformations specified in the SVG file remain separate from the underlying image data. However, embedding images may be required as a final step in some production work-flows.
This java-based extension for Inkscape facilitates image embedding by:
By cropping image data that lies outside the clipping frame or applying jpeg compression, the resulting file size can be reduced significantly. Alternatively, if preserving image quality is a priority jpeg compression can be explicitly avoided.
The extension uses ImageJ to load and manipulate the image data and the Apache Commons Codec library to encode the data for embedding.
This extension was developed to help produce publication quality figures for scientific journals. Comments and suggestions are welcome via Github.
Requirements
Option 1: Build from source
Get the code and build the project using Maven: $ mvn package. Then unpack target/svg-embed-and-crop-<ver>-distr.zip as described below.
Option 2: Download compiled app
svg-embed-and-crop-1.5-distr.zip
Installation
Unpack the entire contents of the archive to the Inkscape extension directory.
For Windows, this is probably something like:
C:\Users\<your user name>\AppData\Roaming\inkscape\extensions\
Note that the AppData directory may be hidden in the file manager. If this is the case, it can be accessed by manually entering the path in the address bar.
For Mac or Linux, this is probably something like:
~/.config/inkscape/extensions/
Run Inkscape. If it was already running, you will have to restart it. The plugin can be run from the menu:
Extensions > Images > Embed and crop images
Images that have already been embedded are ignored.
Only clipping planes created from rectangles are currently supported.
PDFs saved from Inkscape may not include jpeg compression, even if images are embedded in the SVG as jpegs. Additional information is available here. A workaround is to embed images without compression, export a PDF, then compress images in the PDF using The PDF Shrinker.
On some 64bit Windows systems, Inkscape’s Python interpreter fails to recognize the JRE, even if it is correctly registered with the system. A workaround for this issue is to edit svg-embed-and-crop.py to include an absolute path to the JRE.
It is possible to run the app directly from the command line without running Inkscape:
java -classpath <install path> edu.emory.cellbio.svg.EmbedAndCrop [<input>] [-o <output> | -s] [-t <type> [-q <quality>]]
Examples:
java -classpath /path/to/jars/* edu.emory.cellbio.svg.EmbedAndCrop -s -t jpeg -q 0.95 java -classpath /path/to/jars/* edu.emory.cellbio.svg.EmbedAndCrop input.svg -o output.svg