About

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:

  • Automatically identifying all linked images
  • Cropping image data that lies outside the images’ clipping frame
  • Optionally applying jpeg compression
  • Optionally resampling images above a maximum resolution
  • Writing the cropped and possibly compressed image data directly in the SVG file

By cropping image data that lies outside the clipping frame, applying jpeg compression, or resampling to lower resolution, the resulting file size can be reduced significantly. If preserving image quality is a priority jpeg compression and resampling can be explicitly avoided.

The extension uses ImageJ to load 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.

Developed by Benjamin Nanes

Installing the Inkscape Extension

Requirements

  • Inkscape 0.48 or newer
  • Java SE8 or newer

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.6-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

Known Issues

  • Images that have already been embedded are ignored.

  • Only clipping planes created from rectangles are currently supported.

  • In Inkscape versions >= 1.0, non-ASCII characters in text elements may be disrupted on some systems. This is dues to an issue with the new extension system; a fix has been proposed. Workarounds include using Inkscape versions < 1.0 or editing share/inkscape/extensions/inkex/extensions.py in your Inkscape installation as detailed here.

  • 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.

Release Notes

version 1.6

  • Optionally resample images to a maximum resolution to further decrease file size.
  • Improve compatibility with Inkscape versions >= 1.0.

version 1.5

  • Fix resolution of certain relative image paths.
  • Allow output files to be created in new directories.
  • Update initiation script for compatibility with Inkscape 1.0.

version 1.4

  • Fixed bug affecting rotation and skew transformations.

version 1.3

  • Fixed bug causing Java to exit when calling the extension from other Java programs.

version 1.2

  • Fixed bug which resulted in non-default compression quality parameters being ignored.

version 1.1

  • Check for the JRE in some common locations. Partial workaround for problem finding system-registered JRE from 32bit Python interpreter on 64bit Windows.

Running from the Command Line

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>]] [-r [<resolution>]]
  • <install path> – Location of the app’s jar files, ending with /*.
    Ex.: /usr/some-dir/svg-embed-and-crop/*
  • <input> – Path to the input SVG file. If missing, the user will be presented with a file open dialog box.
  • -o <output> – Path to save the output SVG file with embeded images
  • -s – Present the user with a file save dialog to specify the output file
  • Note: If neither -o nor -s is specified, the output is sent to the standard output stream
  • -t <type> – Specify the type of image for encoding. Supported options are png or jpeg. If this is not specified, the user will be presented with a selection dialog.
  • -q <quality> – Quality parameter for jpeg compression. Default value is 0.85.
  • -r <resolution> Maximum image resolution, in pixels per mm. Higher resolution images will be downsampled. If this flag is not given, no resampling will be done. If this flag is given, but no resolution is provided, the default value is 11.811, approximately equal to 300dpi.

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