The only idea which came to my mind was to store the graphic in a box, which allows us to query tex about its height (\ht
), and use that value as the y-coordinate of a corner of the bounding box, then substract the desired height from that value, and use the result as the y-coordinate of the other corner.
I wrote a macro which does those calculations. Here is a MWE:
\documentclass{article}
\usepackage{mwe} % For the sample images
\usepackage{graphicx}
\newcommand{\includeclippedgraphics}[3]{%
% #1 = width
% #2 = height
% #3 = graphics file
\setbox0=\hbox{\includegraphics{#3}}%
\dimen1=\ht0\advance\dimen1 by -#2bp%
\includegraphics[clip, viewport=0 \dimen1 #1 \ht0]{#3}%
}
\begin{document}
% Original image
\includegraphics{example-image}
\vskip 5mm
% Standard crop (from bottom left corner)
\includegraphics[clip, bb=0 0 160 120]{example-image}
\vskip 5mm
% New crop (from upper left corner)
\includeclippedgraphics{160}{120}{example-image}
\end{document}
Result:
Update
I introduced a variation, in which the first argument of the macro (the required width for the image) is optional. If omitted, the native width is used, so you specify only the required vertical size and the bottom of the image gets cropped.
\documentclass{article}
\usepackage{mwe} % For the sample images
\usepackage{graphicx}
\usepackage[margin=5mm]{geometry}
\newcommand{\includeclippedgraphics}[3][0]{%
% #1 = width (optional)
% #2 = height
% #3 = graphics file
\setbox0=\hbox{\includegraphics{#3}}%
\dimen1=\ht0\advance\dimen1 by -#2bp%
\ifnum#1=0\dimen2=\wd0\else\dimen2=#1bp\fi
\includegraphics[clip, viewport=0 \dimen1 \dimen2 \ht0]{#3}%
}
\begin{document}
% Original image
\includegraphics{example-image}
\vskip 5mm
% Standard crop (from bottom left corner)
\includegraphics[clip, bb=0 0 160 120]{example-image}
\vskip 5mm
% New crop (from upper left corner) with optional width set to 160
\includeclippedgraphics[160]{120}{example-image}
\vskip 5mm
% New crop (from upper left corner) with optional width omitted
\includeclippedgraphics{120}{example-image}
\end{document}
And the result: