Produce cards with a PNG background for each card

I need to produce 50 playing cards (60x90mm) with a template available in PSD or PNG or anything else (see picture below).

Here is what I tried:

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm]{geometry}
\usepackage{graphicx}

\newcommand{\card}{
\centerline{\includegraphics{background.png}} % Why isn't it locked on top-left corner
% of the  page ? (it should)
% How to insert the text here, vertically + horizontally centered over the background?
\newpage
}

\begin{document}
\card{This is card 1.}
\card{Hello mister polynomial $x^2+1$.}

\end{document}

Questions:

1. What file format to use for the background template? Would you use PNG? (Goal: I'm producing a PDF that will go to the print worker.)

2. Why doesn't the previous solution overwrite the text over the background? (this is what should happen)?

Update at the end -- give it a try

The background image can be done with tcolorbox and using many of its options, putting it in the background. See the applications of the options how the image is changed.

Considering the dimensions: Please take into account the cutting by your printer, so the margins should be larger, most likely!

\documentclass{article}

\usepackage{blindtext}
\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter]{cardbox}[1][]{enhanced,nobeforeafter,after={\clearpage},width=50mm,height=90mm,halign=center, valign=center, title={This is card \thetcbcounter},colback={white!70!yellow},colbacktitle={cyan},coltitle={black},overlay={%
\begin{tcbclipinterior}
\node[opacity=0.2] (A) at (interior.center) {\includegraphics[width=5cm,height=9cm]{ente}};
\end{tcbclipinterior}
},#1}

\parindent=0pt

\newcommand{\card}[2][]{%
\begin{cardbox}[#1]
#2%
\end{cardbox}%
}
\begin{document}
\pagestyle{empty}

\card{Hello Darkness my old friend}

\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}

\end{document}

\documentclass{article}

\usepackage{blindtext}
\usepackage[most]{tcolorbox}

\tcbset{cardsboxstyle/.style={%
left skip=0em,
right skip=0em,
width=50mm,
height=90mm,
halign=center,
valign=center,
title={This is card \thetcbcounter},
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
colback={white!70!yellow},
colbacktitle={cyan},
coltitle={black}
},
backgroundimage/.style={%
overlay={%
\begin{tcbclipinterior}
\node[opacity=0.1] (A) at (interior.center) {\includegraphics[width=5cm,height=9cm]{ente}};
\end{tcbclipinterior}
}
}
}

\newtcolorbox[auto counter]{cardbox}[1][]{enhanced,nobeforeafter,cardsboxstyle,backgroundimage,#1}

\parindent=0em

\newcommand{\card}[2][]{%
\begin{cardbox}[#1]
#2%
\end{cardbox}%
}
\begin{document}
\pagestyle{empty}

\begin{tcbraster}[raster columns=3,raster column skip=0pt,raster row skip=0pt,raster width=150mm,raster equal height,raster left skip=0pt,raster right skip=0pt]
\card{Hello Duckness my old friend}
\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}
\card{Hello Cuteness my old friend}
\card[colbacktitle={red},overlay={\draw[opacity=0.2,step=1cm,help lines,blue] (interior.north east) grid (interior.south west);}]{Hello Cuteness my old friend}
\card{Hello Duckness my old friend}
\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}
\card{Hello Cuteness my old friend}
\card{Hello Duckness my old friend}
\card[colupper={blue},ams align]{E=mc^{2}}
\end{tcbraster}

\end{document}

• oooooooooh :) – Paulo Cereda Feb 22 '17 at 17:28
• This is upvote pleading ;-) – egreg Feb 22 '17 at 17:29
• @egreg: No, it is just lazyness ... it's my standard image to be included – user31729 Feb 22 '17 at 17:37

Maybe something like this??

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=.1pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}

\newcommand{\card}[1]{\def\stacktype{L}%
\stackon[-.35\paperheight]{%
\raisebox{-.94\paperheight}{\includegraphics[width=1\paperwidth,height=.2\paperheight]{%
example-image}}%
}{\Centerstack{#1}}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=.1pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}

\newcommand{\card}[1]{\def\stacktype{L}%
\stackon[-.45\paperheight]{%
\raisebox{-.94\paperheight}{\includegraphics[width=1\paperwidth,height=\paperheight]{%
example-image}}%
}{\Centerstack{#1}}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}

Note that the .94\paperheight image shift is, essentially, \dimexpr-\paperheight+\baselineskip\relax

P.S.

The following code can supercede both of the above examples, allowing the image height to be independently specified in the \def of \imgheight.

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=0pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}
\def\imgheight{1.0\paperheight}% <---THIS SETS HOW MUCH OF THE CARD THE IMAGE TAKES UP
\newcommand{\card}[1]{\def\stacktype{L}%
\raisebox{\dimexpr-\paperheight+.85\baselineskip\relax}{%
\stackinset{c}{}{c}{\dimexpr.5\paperheight-.5\dimexpr\imgheight\relax}{%
\Centerstack{#1}}{\includegraphics[width=\paperwidth,height=\imgheight]{example-image}}%
}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}
• Thanks Steven! The only little remaining thing is that the image should take the whole 6x9cm space, and the text should be over (on top) of the image. – Basj Feb 22 '17 at 16:12
• @Basj See FOLLOW UP – Steven B. Segletes Feb 22 '17 at 16:14
• Thanks a lot @StevenBSegletes, it works. Last question: would you see a version without any 3rd party packages? (Just for LaTeX learning purposes). This works for the vertical+horizontal centering : \newcommand{\card}[1]{ \topskip0pt \vspace*{\fill} \begin{center} #1 \end{center} \vspace*{\fill} \newpage } but how to insert the PNG image as background? Is there a way to move the cursor at the top of the page to do then \centerline{\includegraphics{background.png}} ? – Basj Feb 23 '17 at 1:50
• @Basj Well, since I wrote stackengine, does that make it a 1st-party package?? :^) I figure you already have geometry and graphic... – Steven B. Segletes Feb 23 '17 at 2:04
• Haha right ;) I was trying with this (rput), but it doesn't work: \newcommand{\card}[1]{ \rput(0,0){\includegraphics{background.png}} \topskip0pt \vspace*{\fill} \begin{center} #1 \end{center} \vspace*{\fill} \newpage. The vertical/horiz alignement of text works, the image is displayed, but unfortunately not at the top left corner... – Basj Feb 23 '17 at 2:07

An eso-pic solution:

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm]{geometry}
\usepackage{graphicx}

\usepackage{eso-pic}

\newcommand{\card}[1]{%
\begin{minipage}[c][\textheight][c]{\textwidth}%
\centering%
#1
\end{minipage}
}

\begin{document}
\noindent
\color{white}
\card{test}%
\card{bla}%
\end{document}

By combining what I've learned thanks to the good answers here and this answer about image background, this finally works (without any 3rd-party package):

\documentclass{minimal}
\usepackage[english]{babel}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=0pt]{geometry}
\usepackage{graphicx}

\newcommand{\card}[1]{
\noindent
\makebox[0pt][l]{\raisebox{-\totalheight}[0pt][0pt]{\includegraphics{background.png}}}
\topskip0pt
\vspace*{\fill}
\begin{center}#1\end{center}
\vspace*{\fill}
\newpage
}

\begin{document}
\card{This is card 3.}
\card{Hello mister polynomial $x^2+1$\\You too}
\end{document}
• If anyone sees even simpler than makebox, raisebox, topskip, I'm interested to learn an even more simple solution! – Basj Feb 23 '17 at 2:20