Is there a way to fill the text of a Tikz node with one random parts of an image?
It would also be nice if each part of the image can also be randomly rotated before to fill the text node.
I don't really care about how to set the size of each parts of the image (as long as the size of the image is large enough compared to the size of the corresponding text to fill). So, for e.g.:
- The size of the parts can be constant and given by the user, e.g.
\def\sizeParts{100pt}, means 100ptx100pt image parts. - Or, the size of the image can be automaticaly calculated regarding to the the size of the corresponding text to fill.
The text in question is actually a list of symbols, let's say: {$\blacksquare$,--,B,$\blacksquare$}
Each symbol of the list is printed horizontally (i.e. inline) with a node per symbol with (from Sandy G' answer here):
\newcommand{\hsp}{.7}
\foreach \s[count=\n from 0] in {$\blacksquare$,--,B,$\blacksquare$}{%
\node[font=\bfseries\Huge] (txt) at (\hsp*\n,0){\s};%
}%
See the expected result at the end of the First attempt section below for an illustrative exemple.
Other end-use details (just in case)
Also, it would be really great if the solution would be compatible with the definition of the nodes as indicated above with a \foreach to loop over a comma-separated list of symbol because then I would like to define a Tikz pic with it in order to perform a Tikz decoration (to easily repeat the pattern along a path, from here):
\usetikzlibrary{decorations.markings}
\tikzset{symbols/.pic={%
\foreach \s[count=\n from 0] in {$\blacksquare$,--,B,$\blacksquare$}{%
\node[font=\bfseries\Huge] (txt) at (\hsp*\n,0){\s};%
}},%
inlinesymbols/.style={%
decoration={markings,mark =between positions 0 and 1 step 30mm % adjust step size here
with {\pic {symbols};}},%
postaction={decorate}}%
}%
\begin{document}
\begin{tikzpicture}
\path[inlinesymbols] (0,-1) -- (4,-1);%
\end{tikzpicture}
\end{document}
And it would be perfect if the solution will be compatible with this Sandy G' \markletters command which permit to generate the comma-separated list of symbol from a text string:
\usepackage{xstring}
\newcommand{\markletters}[1]{\StrLen{#1}[\strlen]\foreach \chr[count=\n from 0] in {1,...,\strlen}{\node[font=\bfseries\Huge] at (\hsp*\n,0){\StrChar{#1}{\chr}};}}%
\tikzset{symbols/.pic={\markletters{$\blacksquare$,--,B,$\blacksquare$}}}%
First attempt
Thanks to this beautiful answer I was able to fill the entire list of symbol with the same image (N.B. this solution seems to only works with jpeg image and not png):
\documentclass{standalone}
\usepackage{environ}
\usepackage{amssymb}% For \blacksquare symbol
\usepackage{tikz}
\usepackage{tikzlings}
\usetikzlibrary{fadings,calc,decorations.pathmorphing}
\NewEnviron{ShadeTikZ}[2][]{\begin{tikzfadingfrompicture}[name=temp]% https://tex.stackexchange.com/a/510465/262081
\begin{scope}[transparent!0,#1]
\BODY
\end{scope}
\end{tikzfadingfrompicture}%
\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}}
[path fading=temp,fit fading=false,fading transform={shift={(X.center)}}]
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}};%
}%
}%
\newcommand{\hsp}{.7}
\begin{document}
\begin{ShadeTikZ}[baseline={(txt.base)}]{example-grid-100x100pt}
\foreach \s[count=\n from 0] in {$\blacksquare$,--,B,$\blacksquare$}{%
\node[font=\bfseries\Huge] (txt) at (\hsp*\n,0){\s};%
}%
\end{ShadeTikZ}
\end{document}
I would prefer this result:
Where each symbol is filled with a different part of the image AND this part is also rotated.

