Get the size that a figure is being rendered

This is a solution that I have recently developed to measure the dimensions of an image

\documentclass[11pt]{article} 
\usepackage{graphicx}

\begin{document}
\newlength{\imageh}
\newlength{\imaged}
\newlength{\imagew}

\newcommand{\setimageh}[1]{
 \settoheight{\imageh}{\usebox{#1}}
}

\newcommand{\setimagew}[1]{
 \settowidth{\imagew}{\usebox{#1}}
}

\newcommand{\setimaged}[1]{
 \settodepth{\imaged}{\usebox{#1}}
}


\newcommand{\ImageDimensions}[1]{
   % create and save the box
  \newsavebox{\Image}
  % Set graphics to fixed size for this example
  \savebox{\Image}{\includegraphics[width=80pt, height=120pt]{#1}}
  \centering\usebox{\Image}\
  \setimageh{\Image}
  \setimagew{\Image}
  \setimaged{\Image}
  \footnotesize
     {\vskip7pt
      The height of the image (#1) is : \the\imageh\\
     The width of the  image (#1) is : \the\imagew\\
     The depth of the  image (#1) is : \the\imaged\\}
}

\ImageDimensions{./DFS8U.png}
\end{document}

It renders as shown below. There are three dimensions shown (width, height and depth)

Example render of measuring picture dimensions


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.


If this is for beamer, an alternative solution might be to look into the \begin{overlayarea} command which should allow you to replace one figure with another while keeping the text outside the overlayarea unmoved. See page 79 et seq. of the beamer user guide.