# Can I color text by using an image, so that the color isn't flat?

I'm using tikz to attempt to make a book cover, and I have a "wallpaper" image that looks like leather (not that I've handled that many leather-bound books). I'm using the node command to place text over the top of it, but none of the colors I've experimented with look decent.

Can I use an image of gold-leaf as the fill/stroke for the text? Or for that matter, for the path lines as well?

I've tried googling for this, but I can't figure out a set of keywords non-generic enough to pull back useful results.

You can "color" the text by anything, including external graphics. This is possible with the fadings library, which has been used e.g. here and here. I downloaded your graphics and called it GoldLeaf.jpg. This graphics gets used in the macro \ShadeText, which does the path fading and adjusts the size of the graphics to fit the text. If you want to use the result in a tikzpicture, use a \savebox as illustrated in the second example.

\documentclass{article}
\usepackage{tikz}
\node[transparent!0] {#2};
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt] (X)
{\phantom{#2}};
\p1=($(X.north east)-(X.south west)+(0.3,0.3)$) in (X.center)
node{\includegraphics[width=\x1,height=\y1]{GoldLeaf.jpg}};}%
}
\newsavebox\WhatEver
\begin{document}

\bigskip
\begin{tikzpicture}
\fill (0,0) rectangle (6,3) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}


In case you do not want to modify the aspect ratio of the picture, you may use the following instead.

\documentclass{article}
\usepackage{tikz}
\node[transparent!0] {#2};
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt] (X)
{\phantom{#2}};
\path[overlay]  node[opacity=0] (img) {\includegraphics{GoldLeaf.jpg}}
let \p1=($(X.north east)-(X.south west)+(0.3,0.3)$),
\p2=($(img.north east)-(img.south west)+(0.3,0.3)$) in
(X.center)  node{\pgfmathsetmacro{\myscale}{max(\x1/\x2,\y1/\y2)}%
\includegraphics[scale=\myscale]{GoldLeaf.jpg}};
}%
}
\newsavebox\WhatEver
\begin{document}

\bigskip
\begin{tikzpicture}
\fill (0,0) rectangle (6,3) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}


ADDENDUM: Of course you can use this beyond \node objects. This is a very quickly written environment that illustrates it. The body of the environment is the stuff you want to "color", the main argument the name of the graphics file that you are going to use for the "coloring" (what is the technically correct term for that?), and the optional argument some pgf keys whose usage gets illustrated. To complete this addendum, the key fading transform that I learned from this very nice answer, was instrumental. It also benefited from a comment by samcarter, who pointed out that the golden leaf looks almost as beautiful as the fur of a marmot. ;-)

\documentclass{article}
\usepackage{environ}
\usepackage{tikz}
\usepackage{tikzlings}
\begin{scope}[transparent!0,#1]
\BODY
\end{scope}
\tikz[#1]{\begin{scope}[local bounding box=X,opacity=0]%
\BODY
\end{scope}
\path[overlay] (X.center)  node[opacity=0,inner sep=0pt] (img) {\includegraphics{#2}}
let \p1=($(X.north east)-(X.south west)+(0.3,0.3)$),
\p2=($(img.north east)-(img.south west)+(0.3,0.3)$) in
(X.center)  node[inner sep=0pt,anchor=center]{\pgfmathsetmacro{\myscale}{max(\x1/\x2,\y1/\y2)}%
\includegraphics[scale=\myscale]{#2}};
}%
}

\newsavebox\WhatEver
\begin{document}
\node[draw,thick,align=center,font=\sffamily\bfseries\Large] (txt)
{2019\\
Hibernation\\[0.5ex]
Awards};
\marmot[yshift=1cm]
\bigskip
\node[draw,thick,align=center,font=\sffamily\bfseries\Large] (txt)
{2019\\
Hibernation\\[0.5ex]
Awards};
\marmot[yshift=1cm]

\begin{tikzpicture}
\fill (0,0) rectangle (6,9) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}


• This works beautifully, thank you. However, I've run into a snafu. When I compile with xelatex (whether or not I have utf8 characters in the title), it stops working but without anything relevant in the log files. Tikz still works because I get the background image. Oct 1 '19 at 15:01
• @JohnO I am sorry, I do not use XeLaTeX a lot (mostly for such reasons). You could ask a new question, which will be seen by some XeLaTeX experts.
– user194703
Oct 1 '19 at 15:05
• @JohnO Actually I tried it out on my updated TeXLive 2019 installation, and I do not have any issues when compiling with xelatex. So I suspect you are using an older installation, or adding something to the document that is not in the above codes.
– user194703
Oct 1 '19 at 17:02
• @JohnO Yes, of course. The way this works is that a node with text is used for path fading. You can use any other TikZ command instead. (Please note that I will be offline for a bit but will be happy to spell this out explicitly a bit later.)
– user194703
Oct 2 '19 at 18:46
• @JohnO I added something along those lines. Of course, there are many ways in which this can be modified but this gives you some basic tool to play with. If you want something very different from that, it might make sense to ask a separate question on that since otherwise it is hard for others to filter out the relevant information.
– user194703
Oct 3 '19 at 3:10