Solution without TikZ
Using text as clip path is supported by package pdfrender
if pdfTeX (or LuaTeX) is running in PDF mode.
\pdfsave
and \pdfrestore
saves and restores the current graphics state, thus that the clipping ends after \pdfrestore
. Since the graphics state include the current transfer matrix (e.g., the current point on the PDF page), the command pair must be used on the same TeX location. Otherwise the TeX coordinate system and the PDF coordinate system would go out of sync.
Full example:
\documentclass{article}
\usepackage{graphicx}
\usepackage{pdfrender}
\usepackage{tgheros}
\usepackage{varwidth}
\newcommand*{\TextImage}[2]{%
\sbox0{%
\sffamily
\bfseries
\begin{varwidth}{\linewidth}%
\uppercase{\ignorespaces#1\ifhmode\unskip\fi}%
\end{varwidth}%
}%
\mbox{%
\pdfsave
% Set clip path
\pdfrender{TextRenderingMode=Clip}%
\rlap{%
\copy0 %
}%
% Now the image or whatever is provided in #2 is used.
\rlap{%
\def\width{\wd0 }%
\def\depth{\dp0 }%
\def\height{\ht0 }%
\def\totalheight{\dimexpr\ht0+\dp0\relax}%
\raisebox{-\dp0}{#2}%
}%
\pdfrestore
% Inform TeX about the text dimensions
\phantom{\copy0}%
}%
}
\begin{document}
\TextImage{%
This text clips the\\
background image%
}{%
\includegraphics[
width=\width,
height=\totalheight,
viewport=0 0 {10mm} {5mm},
]{bg.pdf}%
}
\end{document}

The background image bg.pdf
was generated with:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\pgfmathsetseed{10000}
\foreach \i in {1, ..., 500} {
\pgfmathsetmacro\colred{rnd}
\pgfmathsetmacro\colgreen{rnd}
\pgfmathsetmacro\colblue{rnd}
\definecolor{col}{rgb}{\colred,\colgreen,\colblue}
\pgfmathsetlengthmacro\rad{.1mm + 10mm*rnd/sqrt(\i)}
\fill[col] (rnd, rnd) circle[radius=\rad];
}
\pgfresetboundingbox
\useasboundingbox (0, 0) (1, 1);
\end{tikzpicture}
\end{document}
\documentclass{...}
and ending with\end{document}
.