7

Just a quick question, do you all trim the images by trail and error and plugging numbers there?? Do you use a mark or something to at least keep some reference?

well that's how I do it and is really painful.

Sik
  • 1,331
  • are you asking about cropping off actual portions of an image, or simply reducing the size of the image to the correct bounding box? – barbara beeton Sep 03 '13 at 17:39
  • 1
    Sorry, I was referring to crop off parts of an image. Actually how you guys play to find the right Xs

    \includegraphics[trim = X X X X, clip,height=5]{imageName}

    – Sik Sep 03 '13 at 17:42
  • 2
    Cropping images first with external tools and then including them as is in a document seems to be the smartest way for me. – Thorsten Donig Sep 03 '13 at 17:47

2 Answers2

10

You can use a combination of Drawing a grid on each image inside the array of images and Cropping/Trimming an image with \includegraphics by specifying percentages you can

  1. Draw the image you're interested in including with a grid overlay (showing percentages); and
  2. Trim according to the percentages you're after.

This requires adjustbox (which loads graphicx internally): enter image description here

\documentclass{article}
\usepackage{adjustbox,tikz}% http://ctan.org/pkg/{adjustbox,pgf}
\usetikzlibrary{positioning}

\newcommand\imagegrid[1]{% Grid over image
\begin{tikzpicture}
  \node[anchor=south west,inner sep=0] (A) {#1};
  \begin{scope}[x={(A.south east)},y={(A.north west)}]
  \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
  \foreach \x in {0,1,...,10} { \node [anchor=north,font=\tiny,inner sep=0pt] at (\x/10,0) {\x}; }
  \foreach \y in {0,1,...,10} { \node [anchor=east,font=\tiny,inner sep=0pt] at (0,\y/10) {\y}; }
  \end{scope}%
\end{tikzpicture}%
}

\begin{document}

\imagegrid{\includegraphics{example-image-a}}%

\adjustbox{trim={.35\width} {.25\height} {.35\width} {.25\height},clip}{\includegraphics{example-image-a}}

\end{document}

Of course, you can make the grid finer for more precise measurement & trimming. The default clipping of images via \includegraphics's trim key-value takes input as big points (or bps).

Werner
  • 603,163
5

For PDFs you should take a look at pdfcrop. With this tool, you can crop away all the white parts around the figure. Alternatively you may try the tool with the same name which is not included in your TeX-distro but easy to use as well.

For custom cropping of PDFs I am using Adobe Standard (commercial software) or I crop it with trim=..., clip. If you are fit in Adobe or EPS/PS-tools like ghostscript/ghostviewer, you could manipulate the bounding box of your graphics to your needs. For EPS this can be done in an editor, too. You should know, what you are doing...

Raster-graphics like PNG and JPG can be cropped easily wit GIMP or any other photo editing software. It is always the easiest, to crop as good as possible before inserting to your document. If you are working with screen-shots, you should take some tool to find an already cropped area of the screen. E.g. custom rectangle screen shot of IrfanView.

Vector graphics should be treated in software like Inkscape.

If you have to crop manually, you may want to superpose a help-grid like shown here. This gives you the possibility to have an easier orientation. But it's still a trial and error. (see Werners answer for easy percentage cropping with that grid)

LaRiFaRi
  • 43,807