[pstricks] Change the color of an EPS picture on the fly

Pascal Kockaert Pascal.Kockaert at ulb.ac.be
Thu Jun 19 16:47:58 CEST 2003


\iffalse



Hi,

I have a logo of my university that I would like to include on every slide 
of my presentations... in various colours.

I have followed the tips given in the document written by Keith Reckdahl, 
about the use of EPS graphics with LaTeX, in order to separate the 100kByte 
EPS file (logo.eps) into a 1K file (logo.ps) and a 99K header file (logo.h).

I copy the interesting parts of these two files at the end of this message.

As you will notice, two colours are used in the logo, each of them being 
defined at only one place.

I would like to ask TeX-PS gurus if they know a way to modifiy the 
definition of the two colours (/K /W) from the TeX file, so as to be able 
to change the colour of the background logo according to the colour of the 
actual slide.

I already tried to replace the line
	GS_pswrite_2_0_1001 begin Logo end
with
	GS_pswrite_2_0_1001 begin /K {204 G}! Logo end
but it was a disaster!

Would it be possible to redefine /Logo, so as to write
	GS_pswrite_2_0_1001 begin {204 255 0} {151 17 204} Logo end
in order to define the two colours (/K /W) in the logo.ps file rather than 
in the logo.h file? This way, I could use a different file logo-*.ps file 
for each colour.

Many thanks for any insight!

Pascal Kockaert

P.S. I do not know a lot about PSTricks low-level commands, but I imagine 
that they will be of some use to insert PS code at the right place. 
Otherwise, I would like to apologise for posting on this group !

------------------------------------
Here are the critical parts of my
files (seek for ********* to find the colour definition).
The logo is missing A LOT of lines...
------------------------------------
\fi



%
% Copy the text from here to the end of this message.
% Paste it in a file called UseLogo.tex
% and LaTeX this file...
%
\begin{filecontents}{logo.h}
% This copyright applies to everything until the ``End of copyright''
% Copyright (C) 2002 artofcode LLC, Benicia, CA.  All rights reserved.
%%BeginResource: procset GS_pswrite_2_0_1001
/GS_pswrite_2_0_1001 80 dict dup begin /PageSize 2 array
def/setpagesize{ PageSize aload pop 3 index eq exch 4 index eq
and{ pop pop pop}{ PageSize dup  1 5 -1 roll put 0 4 -1 roll put
dup null eq {false} {dup where} ifelse{ exch get exec} {
pop/setpagedevice where { pop 1 dict dup /PageSize PageSize put
setpagedevice} { /setpage where{ pop PageSize aload pop pageparams
3 {exch pop} repeat setpage}if}ifelse}ifelse}ifelse} bind def
/!{bind def}bind def/#{load def}!/N/counttomark # /rG{3{3 -1 roll
255 div}repeat setrgbcolor}!/G{255 div setgray}!
% ***********************************************
/K{151 204 255 rG}! %Black lines
/W{255 G}!      %White background
%/K{255 G}! % Another example of use. The command G is
%/W{0 G}!   % used for gray definitions, and rG for RGB definitions.
% ***********************************************
/r6{dup 3 -1 roll rG}!/r5{dup 3 1 roll rG}!/r3{dup rG}!
/w/setlinewidth #/J/setlinecap # /j/setlinejoin #/M/setmiterlimit
#/d/setdash #/i/setflat # /m/moveto #/l/lineto #/c/rcurveto # /p{N
2 idiv{N -2 roll rlineto}repeat}! /P{N 0 gt{N -2 roll moveto
p}if}! /h{p closepath}!/H{P closepath}! /lx{0 rlineto}!/ly{0 exch
rlineto}!/v{0 0 6 2 roll c}!/y{2 copy c}! /re{4 -2 roll m exch dup
lx exch ly neg lx h}! /^{3 index neg 3 index neg}! /f{P
fill}!/f*{P eofill}!/s{H stroke}!/S{P stroke}! /q/gsave
#/Q/grestore #/rf{re fill}! /Y{P clip newpath}!/Y*{P eoclip
newpath}!/rY{re Y}! /|={pop exch 4 1 roll 3 array astore cvx exch
1 index def exec}! /|{exch string readstring |=}! /+{dup
type/nametype eq{2 index 7 add -3 bitshift 2 index mul}if}!
/@/currentfile #/${+ @ |}! /B{{2 copy string{readstring pop}aload
pop 4 array astore cvx 3 1 roll}repeat pop pop true}! /Ix{[1 0 0 1
11 -2 roll exch neg exch neg]exch}! /,{true exch Ix
imagemask}!/If{false exch Ix imagemask}!/I{exch Ix image}!
/Ic{exch Ix false 3 colorimage}! /F{/Columns counttomark 3 add -2
roll/Rows exch/K -1/BlackIs1 true>> /CCITTFaxDecode
filter}!/FX{<</EndOfBlock false F}! /X{/ASCII85Decode
filter}!/@X{@ X}!/&2{2 index 2 index}! /@F{@ &2<<F}!/@C{@X &2 FX}!
/$X{+ @X |}!/&4{4 index 4 index}!/$F{+ @ &4<<F |}!/$C{+ @X &4 FX
|}! /IC{3 1 roll 10 dict begin
1{/ImageType/Interpolate/Decode/DataSource
/ImageMatrix/BitsPerComponent/Height/Width}{exch def}forall
currentdict end image}! /~{@ read {pop} if}! end readonly def
%%EndResource
/pagesave null def
% End of copyright
/Logo { GS_pswrite_2_0_1001 begin 595 842 /a4 setpagesize
/pagesave save store 100 dict begin 0.12 0.12 scale gsave mark Q q
0 0 4958 0 0 7017 ^ Y 2.16712 i K 1975.22 2200.09 m -47.73 89.78
32 161.99 42.68 245.07 c -13.14 117.81 18.68 217.86 51.71 317.84 c
-63.98 3.35 p
%
%  [...]
%
4.78 -16.03 36.59 -11.01 49.58 -58.59 c 2.26 -435.94 h S
cleartomark end end pagesave restore showpage
} def    % /Logo
\end{filecontents}
\begin{filecontents}{logo.ps}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 37 35 560 572
%%Creator: AFPL Ghostscript 800 (pswrite)
%%CreationDate: 2003/06/19 09:17:28
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments
GS_pswrite_2_0_1001 begin Logo end
\end{filecontents}
%
%
%
\documentclass{article}
\usepackage{graphicx}
%
\special{header=logo.h}
\newsavebox{\Logo}
\sbox{\Logo}{\includegraphics[width=\linewidth]{logo.ps}}
%
\begin{document}
\fbox{\usebox{\Logo}}
\end{document}




More information about the PSTricks mailing list