1

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.

1

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

0

For the use case you describe, I would probably recommend investigating the LaTex document markup language.

https://en.wikipedia.org/wiki/LaTeX

Essentially, you write markup to give semantic meaning to the content of your document. This semantic markup can then be styled and rendered into a PDF file for digital distribution.

I recommend this for you as you can use LaTex macros such as graphicx and/or adjustbox to specifiy a crop of an included image. When the final document is rendered out, LaTex will only included the uncropped sections of the image in the file size.

Here's a good SE thread with lots of information on learning LaTex: https://tex.stackexchange.com/questions/11/what-are-good-learning-resources-for-a-latex-beginner

  • Thanks for your suggestion - I'm already using LaTeX to assemble the final document. As far as I can tell, cropping with graphicx and/or adjustbox does more or less the same thing as clipping in Inkscape - it masks out the unwanted portions of the image, but does not remove the underlying pixel data (and therefore has no significant effect on file size). Also, I can't see any straightforward way to crop individual sub-images within a more complex figure using LaTeX. – ali_m Jan 14 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.