[Tex/LaTex] Use two different background images, one in odd pages and the other on even pages

backgrounds

I would like to know if there is a code on preambule wich allows me to alternate 2 images, placing one of them as background on even numbered pages, and the other one the odd numbered pages.

Actually I have one image for every page.

I'm using in my preambule:

\usepackage[scale=0]{background}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgVshift{-7.1mm}
\SetBgContents{\includegraphics{image/hkbg.eps}}

And for the fisrt page, I have this line to prevent my background to appear in it:

\NoBgThispage

Best Answer

You can use ifoddpage package:

\documentclass[12pt]{book}
\usepackage{background}
\usepackage{ifoddpage}
\usepackage{kantlipsum}
\backgroundsetup{
scale=1,
opacity=0.3,
angle=0,
color=black,
contents={%
 \checkoddpage
  \ifoddpage
   \includegraphics[width=\paperwidth]{example-image-a}
  \else
   \includegraphics[width=\paperwidth]{example-image-b}
  \fi
}
}

\begin{document}
  \NoBgThispage
  \kant[1-50]
\end{document}

enter image description here

If you don't want to use any extra package simply do this:

\backgroundsetup{
scale=1,
opacity=0.3,
angle=0,
color=black,
contents={%
 \ifodd\value{page}
   \includegraphics[width=\paperwidth]{example-image-a}
  \else
   \includegraphics[width=\paperwidth]{example-image-b}
  \fi
}
}

and remove \usepackage{ifoddpage}.