[Tex/LaTex] How to create a rectangle filled with image using TikZ

tikz-pgf

I want to create a rectangle with tikz and fill it with a predefined image.

For example the following line fill the rectangle with a color. How can I fill with my images instead?

\fill[color=sthlmRed] (0, 4cm) rectangle(\paperwidth, 0.5\paperheight);

Best Answer

The following uses TikZ image fill extensions from the tcolorbox package:

\documentclass{article}

\usepackage[skins]{tcolorbox}

\begin{document}

\noindent\begin{tikzpicture}
\path[fill overzoom image=example-image-a] (0,0) rectangle (\textwidth,4cm);
\end{tikzpicture}

\medskip

\noindent\begin{tikzpicture}
\path[fill stretch image=example-image-b] (0,0) rectangle (\textwidth,4cm);
\end{tikzpicture}

\medskip

\noindent\begin{tikzpicture}
\path[fill tile image*={height=3cm}{example-image-c}] (0,0) rectangle (\textwidth,4cm);
\end{tikzpicture}

\end{document}

enter image description here