I would like to have figures within my document which are as big as possible without breaking the aspect ratio and without breaking the layout. This means the content (including the caption) should still be above the footer. I could, of course, just manually change the height until it fits, but I wonder if there is a better option.

If this doesn't work for the general case, is there a solution that works assuming there are not more than two lines for the caption?

Currently, I use

```
keepaspectratio,width=\linewidth,height=\paperheight

```

as default options for images, but I guess there is something better than `\paperheight`?

While writing this question I found [`\textheight`](https://de.sharelatex.com/learn/Page_size_and_margins) which is much better, but there is still a problem due to the caption.

Minimal example
---------------

### Code

```
\documentclass[a4paper]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage[a4paper, left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}

\usepackage{lastpage}
\usepackage{graphicx}
\usepackage[pagestyles]{titlesec}
\usepackage{float}

% Header and footer
\newpagestyle{mystyle}{%
  \sethead{Something}{is}{here}
  \setfoot{This is left}{middle}{Page \thepage{} of \pageref*{LastPage}}}
\pagestyle{mystyle}

\begin{document}
    % https://de.wikipedia.org/wiki/Datei:Burj_Khalifa.jpg
    \begin{figure}[H]
        \centering
        \includegraphics[keepaspectratio,width=\linewidth,height=\paperheight]{Burj_Khalifa.jpg}
        \caption{A caption}
    \end{figure}
\end{document}

```

### Rendered

[![enter image description here](https://i.stack.imgur.com/pMixL.png)](https://i.stack.imgur.com/pMixL.png)