[Tex/LaTex] Getting ducks in example images

examplesfungraphicstikzducks

This question led to a new package:
duckuments

There are lots of cool example pictures in LaTeX. As far as I'm aware there aren't any good example duck images ;-(

Having ducks in the example images is, of course, essential for increasing the duckness of MWEs all over Tex.SE!

Thus I'd like to know: how do I get the duck to be in the center of an example image?

\documentclass[border=5pt]{standalone}
\usepackage{tikzducks}
\usepackage{graphicx}


\begin{document}
\includegraphics{example-image-a}
\tikz\randuck;
\end{document}

might produce:

enter image description here

There is, however, a problem with putting the duck next to the picture: it looks like a more permanent duck, not there for an example but there for all time. While every good duckument does feature a duck or a dozen, making the reader able to distinguish permanent and example ducks seems essential!

However, currently

\documentclass[border=5pt]{standalone}
\usepackage{tikzducks}
\usepackage{graphicx}


\begin{document}
\includegraphics{example-image-duck} %or with randuck
\tikz\randuck;
\end{document}

produces, with an error message (saying there is no file for the wanted example image):

enter image description here

Here there is no gray border telling the reader not to expect the duck in the final version of the duckument.

Is there any way I can get the two commands:

\includegraphics{example-image-duck}
\includegraphics{example-image-randuck}

To make an image like the one in the first example, but with a duck in the place of the a?

Edit

It would be really cool, but it's probably not going to happen, to have the full tikzducks capabilities:

\includegraphics{example-image-duck[options]}

would thus act like options.

Also Torbjørn T. Posted the command:

\newcommand\ExampleDuck{ \begin{tikzpicture} \node [inner sep=0] {\includegraphics{example-image}}; \begin{scope}[shift={(-1,-1)}] \randuck \end{scope} \end{tikzpicture}}

that just needs an empty example image to be perfect. Now the only big hurdle is feeding includegraphics the result of the command \ExampleDuck if example-image-randuck is being loaded.

Best Answer

Write a document example-duck:

\documentclass[tikz,multi]{standalone}
\usepackage{tikzducks}
\begin{document}
\foreach\x in {1,2,...,100}
{\tikz\randuck;}
\end{document}

and compile it.

Then you can use it like this:

\documentclass{article}
\usepackage{xfp,graphicx}
\newcommand\getduck{\fpeval{randint(1,100)}}

\begin{document}

\includegraphics[page=\getduck]{example-duck}

\includegraphics[page=\getduck]{example-duck}

\includegraphics[page=\getduck]{example-duck}

\end{document}

enter image description here or enter image description here

Edit

as requested in the comments here a more refined example-duck (the pointy head of the witch needs a rather large background):

\documentclass[tikz,multi]{standalone}
\usepackage{tikzducks}
\begin{document}
\foreach\x in {1,2,...,100}
{\begin{tikzpicture}
 \draw[fill=gray!50!white](-0.8,-0.8)rectangle(3,3);
 \draw[gray] (-0.8,-0.8)--(3,3)
             (3,-0.8)--(-0.8,3)
             (-0.8,1.1)--++(3.8,0)
             (1.1,-0.8)--++(0,3.8)
             ;
 \randuck;
 \node [anchor=center,rounded corners,draw=darkgray,opacity=0.5,fill=lightgray,rotate=30,font=\sffamily] at (1.1,1.1) {example duck};
 \end{tikzpicture}}
\end{document}

enter image description here