I have learned from other answers how to use an image file as background and make it transparent. Since my background files do not necessarily have the exact page dimensions (they are provided by users), I want to scale and clip them to fit.
I have found, however, that using
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio,clip]{#1}
does not always scale correctly; landscape-oriented images are scaled so widths fit and then not clipped at all if they are very flat, so a white bar remains. For example, this is using a 1600x750 image on a US Letter landscape page:
\documentclass[landscape]{article}
\usepackage{eso-pic,graphicx}
\pagestyle{empty}
\begin{document}
\AddToShipoutPicture*{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio,clip]{test.png}%
}%
}%
}%
\phantom{lorem ipsum}
\end{document}
How can I tell includegraphics
to always scale the shorter dimension to fit?