# Colorize external pictures using pdflatex

I have several greyscale-pictures that I would like to get colorized within pdflatex (so it will be automatically colorized to a given color, from black-to-white lets say black-to-red).

Is there a way to manipulate external graphics in pdflatex directly?

If this is not possible what way would you recommend to do this for a hundreds of pictures on a linux system? (maybe imagemagick?)

Example:

Should be something like:

• What kind of pictures are they? Vector or raster? Do they have transparent backgrounds? Could you edit your question to include a sample image? – Jake Jun 2 '13 at 21:21
• JPEG like, no transparency, raster, picture added – MrD Jun 2 '13 at 22:13

As far as I know, you can't alter raster images in LaTeX itself. You can, however, call ImageMagic, like you suggested, to transform the image just before it's included. Here's a macro that allows you to write

\redify{image.jpg}


to convert and include the image (shown here in comparison to the unaltered image which is included using \includegraphics{image.jpg}:

ImageMagick is called every time the \redify macro is called, regardless of whether the image has already been converted. If you have many and very large images, you might want to compile the document once with the conversion enabled, and comment out the conversion line from the macro on subsequent runs:

\documentclass{article}
\usepackage{graphicx}
\newcommand{\redify}[2][]{%
\immediate\write18{convert #2 -fill red -tint 40 blurred#2}%
\includegraphics[#1]{blurred#2}%
}

\begin{document}
\includegraphics{image.jpg}\redify{image.jpg}
\end{document}

• Thanks indeed. Actually I had an old function called executeifnewer that uses the \pdffilemoddate routine. This performs very well, as it checks whether the monochrome picture is newer than the redified picture is. If so, it will call the conversion, and if not, it will just include the picture. – MrD Jun 3 '13 at 8:37
• @DL6ER: Ah, that sounds really useful! Could you maybe post (and accept) an answer showing the final macro you ended up using? That would help others who come across a similar issue in the future. – Jake Jun 3 '13 at 15:16
• I will do this soon. – MrD Jun 5 '13 at 14:36

Using ImageMagick is probably the only way of manipulating raster pictures the way I need.

This output is produced by putting

\includegraphics{image.jpg}\redify{image.jpg}


But as Jake mentioned there could be a speed problem:

ImageMagick is called every time the \redify macro is called, regardless of whether the image has already been converted. If you have many and very large images, you might want to compile the document once with the conversion enabled, and comment out the conversion line from the macro on subsequent runs.

Therefore I added the executeifnewer-routine that will check if the source image is newer than the redified one. If so, it will call the conversion, and if not, it will just include the picture. This might save you much time and can easily ported to other (not only conversation) applications.

Here is the code:

\documentclass{article}
\usepackage{graphicx}