I would like to scale an included graphics keeping its aspect ratio. Using
\includegraphics[width=<my width>,height=<my height>,keepaspectratio]{file.jpg}
scaling naturally takes place, but the package calculates which scaling factor is the lower one, the factor to achieve the given width or the factor to achieve the given height (while observing the aspect ratio). That makes sense if you have a given dimension to fill and would like to make sure that the image is fully shown.
However, I would like to scale using the larger of the two scaling factors. In effect, this would fully fill the given dimensions and produce an overlap either in width or height.
In a next step, I then would like to use the adjustbox
to clip the viewport to my desired dimensions, ideally centered on the image. But that's potentially stuff for a separate question.
Edit with solution
Martin essentially answered the question, so the credit is his.
Here, I'd only like to share the actual code I used based on Martin's suggestion. My target width and height are called \mywidth
and \myheight
respectively.
\adjustbox{%
min size={\mywidth}{\myheight},%
Clip*={0.5\width - 0.5\mywidth} {0.5\totalheight - 0.5\myheight}%
{0.5\width + 0.5\mywidth} {0.5\totalheight + 0.5\myheight}%
}{%
\includegraphics[max size={\mywidth}{\myheight}]{file.jpg}%
}%
To get the adjustbox
options working with includegraphics
I used the export
option of the package.