[Tex/LaTex] Censor images and tables

drmgraphicspdf

My publication requires a public and non-public version. I have several figures and tables that I'd like to censor by placing a big colored block on top of it. One page suggested using \colorbox. Unfortunately, this doesn't work for pdf files.

All of the images and tables are simple \includegraphics.

Anyone have a clue?

Update @doncherry, this:

\begin{figure}[h!]
\centering
\colorbox{black}{\includegraphics[width=1\textwidth]{\string"Image".pdf}}
\caption{Google Adwords - BoI}
\end{figure}

produces:

Colorboxed image

Best Answer

You can use the option decodearray to produce a black image with a suitable switch. The image below shows the uncensored and censored image respectively.

enter image description here

The MWE is shown below.

\documentclass[a4paper]{article}
\usepackage{graphicx,caption}
\newif\ifcensored
\begin{document}
\centering
\ifcensored
    \includegraphics[decodearray=
                                 0.0 0.0
                                 0.0 0.0 
                                 0.0 0.0, width=5cm]{amato.jpg}%
\captionof{figure}{censored image}
\else
   \includegraphics[width=5cm]{amato.jpg}% image with RGB colors
   \captionof{figure}{uncensored}
\fi
\includegraphics[decodearray=
                                 0.0 0.0
                                 0.0 0.0 
                                 0.0 0.0, width=5cm]{amato.jpg}%
\captionof{figure}{censored image}
\includegraphics[width=5cm]{amato.jpg}% image with RGB colors
\captionof{figure}{uncensored}
\end{document}

The code works well with .png as well as .jpg images. Details for decodearray can be found in the PDF Reference Manual. As a matter of interest if the values of the pairs have values other than zero one can manipulate the color channels, producing a reddish image for example.

Of course you will need to incorporate a suitable command to replace \includegraphics. One such approach is to define:

\DeclareRobustCommand{\cimage}[3][]{
\ifcensored
    \includegraphics[decodearray=
                                 0.0 0.0
                                 0.0 0.0 
                                 0.0 0.0, width=5cm]{#2}%
\captionof{figure}{#3(censored image)}
\else
   \includegraphics[width=5cm]{#2}% image with RGB colors
   \captionof{figure}{#3}
\fi
}

To censor the images you type,

\censoredtrue
\cimage{amato.jpg}{A caption for your figure}

Note that the image data is still included in the pdf and can possibly be extracted, so use with caution or in cases where paper copies only will be circulated.

Related Question