# Insert image so that it fills the rest of the page while not fall below a minimum size

I'm trying to make a command that adds images to page in a way that fill the rest of the page. I'm using code from How to define a figure size so that it consumes the rest of a page? and it works. But I noticed that sometimes the image will be very small when there is little space left, so I wanted to make it conditional - if there is more than 1/3 of the page left, fit the image, otherwise just put the bigger image on the next page - but I can't get the if to work. I'm new with LaTeX, can you help me make it work?

Here's the code:

\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}
\newcommand{\imgFill}[1]{\begin{center}
\ifnum \measurepage<0.3*\textheigth \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{#1}
\else \includegraphics[height=\measurepage,width=\textwidth,keepaspectratio]{#1} \fi
\end{center}
}

• \measurepage is a dimension not a number, so you need to use \ifdim. Beside this: don't show only snippets, a full document is much easier to test. – Ulrike Fischer Dec 6 '18 at 10:00

\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}