3

I'd like to fill a page with a picture (to the extent possible while preserving the picture's aspect ratio).

I want the picture to fill the page, extending beyond the margins. (I want non-zero margins in general, on pages that will have text.) The page will only be a screen, not printed paper.

Here's my best attempt; there are several problems:

  • the top of the picture is clipped
  • there's a little blank space at the bottom
  • the whole thing appears on page 2, the first page being skipped
    \documentclass{article}
    \usepackage{graphicx}
    \usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

    \newcommand\fillpic[1]{%
      \begin{minipage}[t][\textheight][c]{\textwidth}
         \vss%
         \null\hfill%
         \includegraphics*[keepaspectratio=true,%
         width=\linewidth,height=\paperheight]{#1}%
         \hfill\null%
         \vss%
       \end{minipage}}

    \begin{document}
    \fillpic{example-image-a}%
    \end{document}

dedded
  • 2,236

2 Answers2

1

I will be happy to delete this, but are you looking for something like this?

\documentclass{article}
\usepackage{tikz}
\usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

\newcommand\fillpic[1]{%
  \setbox0\hbox{\includegraphics*[keepaspectratio=true,]{#1}}%
  % ^ this measures the dimensions of the graphics
  \begin{tikzpicture}[overlay,%<-allow the picture to go over the page borders
   remember picture%<-access to page anchors like page.center
   ]
  \pgfmathsetmacro{\myscale}{min(\the\paperwidth/\the\wd0,\the\paperheight/\the\ht0)}%   
  % ^ compute the scale factor as the minimum of ... to make sure the graphics does not overshoot
   \node at (current page.center){\includegraphics*[keepaspectratio=true,%
    scale=\myscale]{#1}};% <- add the graphics with the appropriate scale
    % at the center of the page.
  \end{tikzpicture}}

\begin{document}
\fillpic{example-image-a}%
\clearpage
\fillpic{example-image-16x9}%
\end{document}
  • Well, that seems to work, but I don't understand it. Would you be willing to annotate it? (And it would be nice to stop the animation) – dedded Nov 13 '19 at 02:21
  • @dedded done... –  Nov 13 '19 at 03:01
  • 1
    Got it, the key is that tikz can find the center of the page, and place an image there. It turns out that the measuring and explicit scaling aren't needed, passing width=\paperwidth,height=\paperheight to includegraphics can accomplish the scaling. Thanks! – dedded Nov 13 '19 at 03:12
1

You can place content in the BackGround (or the ForeGround) of the current page (using the *-version of \AddToShipoutPictureBG) using eso-pic:

enter image description here

\documentclass{article}

\usepackage{graphicx,eso-pic}
\usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

\newcommand{\fillpic}[2][]{%
  \mbox{}\ignorespaces% Put something (\mbox{}) on the page
  \AddToShipoutPictureBG*{% Place image in the BackGround of _this_ page
    \AtPageCenter{% Place the image at the centre of the page
      \makebox[0pt]{% Set the image inside a 0pt-width box that is horizontally centred (by default)
        \raisebox{-.5\height}{% Move the image vertically centred on the page
          \includegraphics[
            keepaspectratio=true,
            width=\paperwidth,
            height=\paperheight,
            #1
          ]{#2}%
        }% \raisebox
      }% \makebox
    }% \AtPageCenter
  }% \AddToShipoutPictureBG*
}

\begin{document}

\fillpic{example-image-a}

\end{document}

I've added optional arguments to \fillpic[<img parameters>][<image>}.

Werner
  • 603,163
  • This answer works with both pdflatex and lualatex, so it might be preferable. (the tikz macro has the image almost entirely missing with pdflatex, which worked for me as I was using lualatex anyhow.) – dedded Nov 13 '19 at 13:11