[Tex/LaTex] Get the size that a figure is being rendered

graphicsscalingspacing

Suppose I have a figure in my LaTeX document:

\begin{figure}
  \includegraphics[scale=0.5]{some_graphic}
\end{figure}

My question is pretty simple: Is there a way to get the size that some_graphic will be rendered to in points/inches/whatever unit into a variable for use in the rest of the document? Here's a slightly more reasonable motivating example from beamer:

\begin{frame}
  \begin{block} \begin{block}<2->{Title}
    Text on the first part.
    \only<2>{
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \vspace{2.19in}  % Would be nice not to have to tweak this value manually
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    }
    \only<3>{
    \begin{figure}\centering
      \includegraphics[width=0.60\textwidth,clip,trim=0in 2.1in 0in 0in]{figures/scheme}
    \end{figure}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \vspace{0.775in} % Would be nice not to have to tweak this value manually
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    }   
    \only<4>{
    \begin{figure}\centering
      \includegraphics[width=0.60\textwidth]{figures/scheme_new}
    \end{figure}
    }
  \end{block}
\end{frame}

In other words, I realize that there is a way around this problem manually, by tweaking the vspace values, but that's not very reasonable, and it seems to go against the whole idea behind TeX of letting the rendering engine do the work.

Best Answer

The literal method for doing this looks something like as follows:

\usepackage{calc}
...
\def\mygraphic{\includegraphics{...}}

\newlength\graphicheight
\setlength\graphicheight{\heightof{\mygraphic}}
% OR: \settoheight\graphicheight{\mygraphic}
...
\mygraphic % to insert the graphic
...
\vspace{\graphicheight} % whitespace same size as the graphic

But there is also the \phantom command which creates an empty box of the same size as its contents, which might suit your specific circumstances better:

\mygraphic % insert the graphic
...
\phantom{\mygraphic} % insert a blank box of the same size

Additionally, \includegraphics takes a draft option to replace individual images by placeholders, so

\def\mygraphic\{includegraphics[draft]{...}}

might perform better than including the actual image.