# Changing color in an eps file from within LaTeX

We have an EPS file with a logo in one color. Is it possible to somehow manipulate this color from within LaTeX? We need this logo in different colors for different series of one imprint.

Edit:

This is the logo:

http://hpsg.fu-berlin.de/~stefan/transfer/Logo_Buchcover_hellblau.eps

• It's probably easier to manually edit the postscript code, or do it using sed. Can you make it available for download? Jun 14, 2013 at 20:27
• Stephan, Could you place the image in a long-term storage? The link above no longer works. Nov 27, 2020 at 17:38

There is a trick with the graphics driver file pdftex.def for pdfTeX in PDF mode. If the PDF image does not contain color settings, then pdftex.def does not enforce black, but uses the current color.

1. First we need to convert the EPS file to PDF:

ps2pdf -dEPSCrop -dCompressPages=false Logo_Buchcover_hellblau.eps Logo_Buchcover.pdf


Option -dCompressPages=false disables the compression for the page contents, because we need to manipulate it in the next step. Because the image does not contain many operators, there is no much gain in compressing anyway.

2. The color setting needs to be disabled. However care is needed. PDF records the positions of its indirect objects in a cross reference table, we only change a byte and do not add or remove bytes to keep the PDF structures intact.

Identify the line:

0.599609 0.0499878 0.0499878 0 k


k is the operator for setting a CMYK color. The percent % is the comment character in PDF (PostScript, TeX), thus we change the first 0 to %:

%.599609 0.0499878 0.0499878 0 k


The editor that is used to modify the byte must not change anything else (line ends, tabulators, ...). If in doubt, then also a hex editor will do.

3. Now we can use the image in pdfLaTeX:

\documentclass[pdftex]{article}
% The trick does not work for other drivers
\usepackage{graphicx}
\usepackage{color}

\begin{document}
\includegraphics{Logo_Buchcover}
\textcolor{red}{\includegraphics{Logo_Buchcover}}
\textcolor{blue}{\includegraphics{Logo_Buchcover}}
\end{document}


This might not work with any eps, but for not very complex vector graphics, this workflow can be used:

• convert Logob.eps to Asymptote with pstoedit -f asy Logob.eps Logob.asy;
• simplify asy code and add commands to change color where appropriate.

For the logo provided pstoedit found that DIN-Regular font is used for the text.

Following Logob.tex contains a procedure to draw the logo in asydef, which accepts parameters for the background color, colors of the books and colors of the three lines of text.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{dinregular.ttf}
\usepackage[inline]{asymptote}
\begin{asydef}
size(88,43);
import pstoedit;
void logo(pen bgPen=white,pen[] bookPen=new pen[]{black}, pen[] textPen=bookPen){
filldraw(box((0,0),(89,43)),bgPen,bgPen);
textpen=textPen[0];
textpen += fontsize(7.84581);

label(baseline("language"),(56.229,33),align,textpen);

textpen=textPen[1%textPen.length];
textpen += fontsize(8.02011);

label(baseline("science"),(56.229,23.5),align,textpen);

textpen=textPen[2%textPen.length];
textpen += fontsize(8.02011);
label(baseline("press"),(56.229,14),align,textpen);

currentpen += 0.5bp;
currentpen += squarecap;
currentpen += miterjoin;
currentpen += linetype(" ",false);

fill((14.0195,42.5195)--(0,2.47656)--(7.07031,0)
--(21.0898,40.043)--cycle,bookPen[0%bookPen.length]);
fill((21.0859,42.4258)--(21.0859,0)--(28.5781,0)
--(28.5781,42.4258)--cycle,bookPen[1%bookPen.length]);
fill((29.5742,42.4258)--(29.5742,0)--(37.0664,0)
--(37.0664,42.4258)--cycle,bookPen[2%bookPen.length]);
fill((38.0625,33.9648)--(38.0625,0)--(45.5547,0)
--(45.5547,33.9648)--cycle,bookPen[3%bookPen.length]);
fill((46.5508,42.4258)--(46.5508,0)--(54.043,0)
--(54.043,42.4258)--cycle,bookPen[4%bookPen.length]);
}
\end{asydef}
\begin{document}
\begin{minipage}{88bp}
\begin{asy}
logo();
\end{asy}
\end{minipage}
\begin{minipage}{88bp}
\begin{asy}
logo(bgPen=gray,bookPen=new pen[]{white},textPen=new pen[]{black});
\end{asy}
\end{minipage}
%
\begin{minipage}{88bp}
\begin{asy}
logo(bgPen=lightblue+opacity(0.3),bookPen=new pen[]{green,orange});
\end{asy}
\end{minipage}
%
\begin{minipage}{88bp}
\begin{asy}
logo(bgPen=lightgreen+opacity(0.3),bookPen=new pen[]{red,green,darkblue,orange,yellow}
,textPen=new pen[]{red,green,blue});
\end{asy}
\end{minipage}
\end{document}


To process it with xelatex, run:

xelatex Logob.tex
asy -f pdf -tex=xelatex Logob-*.asy
xelatex Logob.tex

• At first this might get difficult, but in the end this is a brilliant idea! Thanks a lot! :)
– user101590
May 7, 2016 at 6:31