I've been messing with this all morning, so I thought I'd post my minimal working example.
Basically, it can get a bit difficult to find the coordinates of a rectangle we want to zoom/crop in Latex, especially since image coordinates are typically expressed in pixels in respect to upper left corner origin (here a GIMP grid view of the attached image, used in the test): whereas the arguments to viewport or trim of \includegraphics are expressed in bp (big points).
So, I thought of using overpic's grid, as a help tool to get approximate coordinates of the desired rectangle to be zoomed/cropped. Overpic was chosen because when it is in absolute mode, you can change easily the units of the grid (mm, pt - any Latex unit). Additionally, overpic's origin of coordinate system is the same as for the viewport argument - bottom left corner.
Basically, this is all very doable - as long as you don't happen to use the width= argument together with grid in overpic - because then the grid will refer to the newly set width, and display the completely wrong numbers !

So, this minimal working example will basically generate this page: and the code is below..
Hope this can help someone,
Cheers!
PS: If the image you're measuring using the grid is too big and you need to move the graphic off-page, you can use something like negative \hspace:
Code: Select all
\hspace{-2in}\begin{overpic}[grid,unit=1bp]{st02softwaregrconv-img/st02softwaregrconv-img002}\end{overpic}
Code: Select all
% cropsizetest.tex
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc} %support unicode chars direct without crashing :)
\usepackage{graphicx}
\usepackage[abs]{overpic} % must be in abs mode for changing units; else wrong numbers on grid !
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\footnotesize
\begin{enumerate}
\item {The png image is 400x200 pixels}
\item {In image coordinate system (origin in upper left corner), the desired rect has x=50,y=50 (px) upper left corner position, and size 150x80 px}
\end{enumerate}
First an overpic ({\em do NOT use ,width=4.6835in in overpic arguments, when using grid in this way - it messes the lengths up!}) - to generate a grid and find coordinates for cropping, for unit=1bp:
\newline
\begin{figure}[!h]
\begin{overpic}[grid,unit=1bp]{imgtest.png}\end{overpic}% DO NOT use ,width=4.6835in in args here!
\end{figure}
Overpic reports width 400 bp width and 200 bp height (same as pixel sizes).
\newline
In the overpic coord. system (origin in bottom left corner), the bottom left corner of the desired rect should be around x=50,y=70; and its upper right corner at approx x=200,y=150 (bp). Lets try that as viewport=50 70 200 150 ({\em since viewport is also based on origin in bottom left corner coord. system, just as overpic}):
\begin{figure}[!h]
\includegraphics[viewport=50 70 200 150,width=1in,clip]{imgtest.png}
%\includegraphics*[viewport=50 70 200 150,width=1in]{imgtest.png} %alternative with starred version
\end{figure}
Yup, did get the desired rect. \newline
Let's see now what would've happened if we used the ',width' arg in overpic:
\begin{figure}[!h]
\begin{overpic}[grid,width=2.74in,unit=1bp]{imgtest.png}\end{overpic}%
\end{figure}
Bad :)
\end{document}