%% 
%% This is file `wallpaper.sty' v 1.20
%%
%% Author Michael H.F. Wilkinson 
%%   September 26, 2007
%% 
%% Create background, either centered, tiled, or in any corner   
%% relies heavily on eso-pic.sty, corrects for changes in \hoffset 
%% by classes such as sciposter.cls
%% Problems, bugs and comments to 
%%        michael@cs.rug.nl
%% version 1.20, 2007/09/26:
%%               - Changes to \(This)TileWallPaper allow automatic 
%%                 aspect-ratio detection by the package
%%
%% version 1.10, 2006/04/21:
%%               - Commands added for corner wallpapers 
%%
%% version 1.01, 2005/01/18:
%%               - \providecommand{\LenToUnit} included to be compatible
%%                  with earlier versions of eso-pic.sty
%%
%% version 1.00, 2004/12/22:
%%               - first release
%%
%%
\ProvidesPackage{wallpaper}[2007/09/26, v1.20 easy wallpaper formatting (MHFW)]
\NeedsTeXFormat{LaTeX2e}[1995/06/01]

\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{eso-pic}
\RequirePackage{graphicx}

\providecommand{\LenToUnit}[1]{#1\@gobble}


\newlength{\wpXoffset}
\setlength{\wpXoffset}{-\hoffset}
\newlength{\wpYoffset}
\setlength{\wpYoffset}{0pt}
\newlength{\tileXoffset}
\newlength{\tileYoffset}
\newlength{\tilewidth}
\newlength{\tileheight}
\newlength{\tileX}
\newlength{\tileY}

\newcommand{\LLCornerWallPaper}[2]{%
\AddToShipoutPicture{%
  \AtPageLowerLeft{%
    \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
                     keepaspectratio]{#2}%
    }
  }
}

\newcommand{\ThisLLCornerWallPaper}[2]{%
\AddToShipoutPicture*{%
  \AtPageLowerLeft{%
    \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
                     keepaspectratio]{#2}%
    }
  }
}

\newcommand{\ULCornerWallPaper}[2]{%
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{#1\paperwidth}{%       
        \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
        \vfill%
      }
    }
  }
}

\newcommand{\ThisULCornerWallPaper}[2]{%
  \AddToShipoutPicture*{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{#1\paperwidth}{%       
        \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
        \vfill%
      }
    }
  }
}

\newcommand{\LRCornerWallPaper}[2]{%
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \parbox[b]{\paperwidth}{%       
        \hfill \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
      }
    }
  }
}

\newcommand{\ThisLRCornerWallPaper}[2]{%
  \AddToShipoutPicture*{%
    \AtPageLowerLeft{%
      \parbox[b]{\paperwidth}{%       
        \hfill \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
      }
    }
  }
}

\newcommand{\URCornerWallPaper}[2]{%
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{\paperwidth}{%       
        \hfill \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
        \vfill%
      }
    }
  }
}

\newcommand{\ThisURCornerWallPaper}[2]{%
  \AddToShipoutPicture*{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{\paperwidth}{%       
        \hfill \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
        keepaspectratio]{#2}%
        \vfill%
      }
    }
  }
}

\newcommand{\CenterWallPaper}[2]{%
\AddToShipoutPicture{\put(\LenToUnit{\wpXoffset},\LenToUnit{\wpYoffset}){%
     \parbox[b][\paperheight]{\paperwidth}{%       
       \vfill
       \centering
       \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
                        keepaspectratio]{#2}%
       \vfill
     }}
  }
}  

\newcommand{\ThisCenterWallPaper}[2]{%
\AddToShipoutPicture*{\put(\LenToUnit{\wpXoffset},\LenToUnit{\wpYoffset}){%
     \parbox[b][\paperheight]{\paperwidth}{%       
       \vfill
       \centering
       \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
                        keepaspectratio]{#2}%
       \vfill
     }}}
}  



\newcommand{\TileSquareWallPaper}[2]{%
\AddToShipoutPicture{%
  \begingroup
    \setlength{\tileYoffset}{\wpYoffset}
    \setlength{\tilewidth}{\paperwidth/#1}%
    \setlength{\tileheight}{\tilewidth}%
    \setlength{\tileY}{0pt}%
    \whiledo{\lengthtest{\tileY < \paperheight}}{% 
      \setlength{\tileX}{0pt}%
      \setlength{\tileXoffset}{\wpXoffset}%
      \whiledo{\lengthtest{\tileX < \paperwidth}}{% 
        \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
          \includegraphics[height=\tileheight,width=\tilewidth]{#2}}%
        \addtolength{\tileX}{\tilewidth}
        \addtolength{\tileXoffset}{\tilewidth}
      }%
      \addtolength{\tileY}{\tileheight}
      \addtolength{\tileYoffset}{\tileheight}
    }%
  \endgroup  
}%
}

\newcommand{\ThisTileSquareWallPaper}[2]{%
\AddToShipoutPicture*{%
  \begingroup
    \setlength{\tileYoffset}{\wpYoffset}
    \setlength{\tilewidth}{\paperwidth/#1}%
    \setlength{\tileheight}{\tilewidth}%
    \setlength{\tileY}{0pt}%
    \whiledo{\lengthtest{\tileY < \paperheight}}{% 
      \setlength{\tileX}{0pt}%
      \setlength{\tileXoffset}{\wpXoffset}%
      \whiledo{\lengthtest{\tileX < \paperwidth}}{% 
        \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
          \includegraphics[height=\tileheight,width=\tilewidth]{#2}}%
        \addtolength{\tileX}{\tilewidth}
        \addtolength{\tileXoffset}{\tilewidth}
      }%
      \addtolength{\tileY}{\tileheight}
      \addtolength{\tileYoffset}{\tileheight}
    }%
  \endgroup  
}%
}


\newcommand{\TileWallPaper}[3]{%
\AddToShipoutPicture{%
  \begingroup
    \setlength{\tileYoffset}{\wpYoffset}
    \setlength{\tilewidth}{#1}%
    \setlength{\tileheight}{#2}%
    \setlength{\tileY}{0pt}%
    \whiledo{\lengthtest{\tileY < \paperheight}}{% 
      \setlength{\tileX}{0pt}%
      \setlength{\tileXoffset}{\wpXoffset}%
      \whiledo{\lengthtest{\tileX < \paperwidth}}{% 
        \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
          \includegraphics[height=\tileheight,width=\tilewidth]{#3}}%
        \addtolength{\tileX}{\tilewidth}
        \addtolength{\tileXoffset}{\tilewidth}
      }%
      \addtolength{\tileY}{\tileheight}
      \addtolength{\tileYoffset}{\tileheight}
    }%
  \endgroup  
}%
}

\newcommand{\ThisTileWallPaper}[3]{%
\AddToShipoutPicture*{%
  \begingroup
    \setlength{\tileYoffset}{\wpYoffset}
    \setlength{\tilewidth}{#1}%
    \setlength{\tileheight}{#2}%
    \setlength{\tileY}{0pt}%
    \whiledo{\lengthtest{\tileY < \paperheight}}{% 
      \setlength{\tileX}{0pt}%
      \setlength{\tileXoffset}{\wpXoffset}%
      \whiledo{\lengthtest{\tileX < \paperwidth}}{% 
        \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
          \includegraphics[height=\tileheight,width=\tilewidth]{#3}}%
        \addtolength{\tileX}{\tilewidth}
        \addtolength{\tileXoffset}{\tilewidth}
      }%
      \addtolength{\tileY}{\tileheight}
      \addtolength{\tileYoffset}{\tileheight}
    }%
  \endgroup  
}%
}

\newcommand{\ClearWallPaper}{\ClearShipoutPicture}