38

Say I have an image my_image.png that I am loading in my LaTeX document using:

\begin{figure}
\includegraphics[width=0.5cm]{my_image.png}}
\end{figure}

Is there a way of telling LaTeX to only render a specific rectangular portion (in percentages) of the original image?

For example, say I want to just render a cropped image:

  • Trim 5% of the original image width from the left
  • Trim 10% of the original image width from the right
  • Trim 15% of the original image height from the top
  • Trim 20% of the original image height from the bottom
  • have a look at the package adjustbox with the option export. – Marco Daniel Apr 20 '12 at 14:10
  • 2
    Note that all clipping (or cropping) is done by telling the document viewer not to display these parts. The whole image is still be stored in the output file and might be extracted by readers with more advanced software. So it is not recommended to use this technique to hide secret parts of the image. In such cases the image should be cropped manually beforehand by an external tool. – Martin Scharrer Dec 07 '17 at 07:29

1 Answers1

43
\documentclass{article}
\usepackage{graphicx}
\usepackage{adjustbox}

\begin{document}

\adjustbox{trim={.05\width} {.2\height} {0.1\width} {.15\height},clip}%
  {\includegraphics[width=0.5cm]{cupdot.png}}

\end{document}

Since \includegraphics produces no depth, you can use the fact that \adjustbox knows the \width and the \height of the image.

egreg
  • 1,121,712
  • 3
    Can be written a little shorter with newer versions of adjustbox: \adjincludegraphics[width=0.5cm,Clip={.05\width} {.2\height} {0.1\width} {.15\height}]{cupdot.png} (note the uppercase Clip). – Martin Scharrer Dec 07 '17 at 07:25