5

Is there a way to use black-and-white images in a PDF as transparency masks for vector content? I know that I can use

\pgfdeclaremask{maskname}{maskfile}
\pgfimage[mask=maskname]{imagefile}

for hard (1-bit) or soft transparency masks, but only with raster images maskfile and imagefile of the same dimension.

If I understand correctly, that is only a requirement of TikZ/PGF, not PDF. At least I'm sure that PDF allows bitmap stencils of different pixel size over other bitmap images (that's what Xerox copiers do for scans to PDF).

However, is there a way to do the equivalent of

\pgfdeclaremask[maskname]{maskfile}
\begin{tikzpicture}
  \fill[mask=maskname,color=somecolor] (0,0) rectangle (100,100);
\end{tikzpicture}

to have the opaque parts of the mask drawn in somecolor, or even a way to mask arbitrary content with an alpha channel taken from a grayscale picture?

In case it matters, I'm currently using LuaLaTeX, but that's not a strict requirement.

akobel
  • 445
  • 1
  • Indeed, the approach described there works. Thanks! In short for further reference: \begin{tikzfadingfrompicture}[name=mask] \node[fill=transparent!0, draw=none, inner sep=0pt] {\pgfimage{img}}\end{tikzfadingfrompicture} ... \path[scope fading=mask, fit fading=false, <fading transform={...}>]; \fill[color=<color>] <coords> rectangle <coords>; – akobel Mar 01 '16 at 12:57
  • Addendum: be careful with that; it turned out that a page of such a PDF file did not print on a Xerox printer which AFAICS handles the PDF internally. So if in doubt and you are preparing for press, stick to traditional graphics without fancy stuff, and rather sacrifice file size... – akobel Apr 19 '16 at 10:41

0 Answers0