Is there an automated way to remove cropped regions of embedded images in order to optimize the size of an Inkscape SVG file?

I am preparing some figures for a scientific publication using Inkscape. These figures are SVGs containing embedded bitmap images that are quite large, but only a small rectangular clipped region of each image is actually displayed. An example image is shown below (the SVG itself is available here):

enter image description here

These images will ultimately be embedded into a PDF document. In order to keep the document file size reasonably small, I’m looking for a way to reduce the overall file size by “throwing out” pixels that fall outside of the clipping rectangles.

I could do this by manually cropping each image in an external editor, then re-importing it into the SVG, repositioning it, scaling it etc. to match the current clip box. This is quite tedious, though. I’d ideally like to be able to convert quickly and easily between a “working copy”, where I can edit the clipping rectangles, and an “optimized copy” that only contains the pixels that I actually want to display.

Is there an automated way to do this using Inkscape or some other tool? I’d also be interested in any potential solutions that operate on PDF or EPS files.

Answer

1) Bitmap copy workaround:

  • Select the bitmap image with the clipping mask and press ALT + B (create a bitmap copy).
  • Delete the original image.

The resolution of the bitmap copy can be set in the Edit > Preferences > Bitmaps menu.

2) Filter workaround:

  • Apply dummy filters to the clipped bitmap images (e.g. Filters > Fill and Transparency > Blend with default options)
  • Set the Rasterize filter effects checkbox in the PDF export window.

3) Embed and crop extension:

http://cellbio.emory.edu/bnanes/svg-embed-and-crop/

The biggest issue of the extension is that it does not work if the raster image is already embedded (and not linked to a file).

Attribution
Source : Link , Question Author : ali_m , Answer Author : fuge

Leave a Comment