Crop an image in LaTeX (trim, clip)

\includegraphics[trim=20 10 60 30,clip]{image.png} cuts 20 bp off the left, 10 bp off the bottom, 60 bp off the right and 30 bp off the top. The order is always left, bottom, right, top.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{graphicx}

Cut off the edges with trim

The four values are separated by spaces. A number without a unit is in bp (big points, 1/72 inch); other units work as well, for example trim=1cm 0cm 1cm 0cm. clip hides the trimmed parts.

\includegraphics[trim=20 10 60 30,clip]{image.png}
Result
The compiled example

Crop and scale

The trim values refer to the natural size of the image, not to the size on the page. A width after them applies to the cropped result: here the remaining part of the image becomes 5 cm wide.

\includegraphics[trim=20 10 60 30,clip,width=5cm]{image.png}
Result
The compiled example

Select a region with viewport

viewport names the part to keep instead of the parts to remove. Its four values are the coordinates of the lower left and the upper right corner of the region, measured from the lower left corner of the image.

\includegraphics[viewport=20 10 260 170,clip]{image.png}
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages