%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IMAGE by Anthony Phan.
% file: image.tex (system-dependent control sequences)
% last modification: November 12, 2000.
%
% SYSTEM DEPENDENT.
% It works on some decent GNU-Linux systems.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode`\@=11

\def\imagescale#1{\def\@imagesf{#1 }}

\imagescale{1}

\def\@giftops#1{giftopnm #1 |
	    pnmtops -scale \@imagesf -dpi 600 -nocenter -noturn}
\def\@jpgtops#1{djpeg -pnm #1 |
	    pnmtops -scale \@imagesf -dpi 600 -nocenter -noturn}

\newif\if@found

\def\ifsuffix\if#1\in#2{\def\@suffix{}% default suffix is void
	%
	% first part: getting the suffix
	%
	\def\next##1.##2\end{\ifx##2\undefined
		\def\@suffix{##1}\else\next##2\end\fi}%
	\next#1.\undefined\end
	%
	% second part: check if \@suffix is in #2
	%
	\@foundfalse
	\def\next##1,##2\end{\def\@@suffix{##1}%
		\ifx\@suffix\@@suffix\@foundtrue
		\else\ifx##2\undefined\else\next##2\end\fi
		\fi}%
	\next#2,\undefined\end
	\if@found}

\def\imagebox#1{%
	\image@size#1 size=0x0 \end
	\image@src#1 src=??? \end
	\vbox to \dimen@ii{\vss
	\hbox to \dimen@i{\special{psfile="`\import@image"}\hss}}}

\def\image@src#1src=#2 #3\end{%
	\ifsuffix\if #2\in{jpg,jpeg,JPG,JPEG}%
		\edef\import@image{\@jpgtops{#2}}%
	\else\ifsuffix\if #2\in{gif,GIF}%
			\edef\import@image{\@giftops{#2}}%
		\else\let\import@image=\relax
			\message{[unknown image format]}%
		\fi
	\fi}

\def\image@size#1size=#2x#3 #4\end{%
	\dimen@i=1in\divide\dimen@i by 15\multiply\dimen@i by #2
	\dimen@i=\@imagesf\dimen@i\divide\dimen@i by 5
	\dimen@ii=1in\divide\dimen@ii by 15\multiply\dimen@ii by #3
	\dimen@ii=\@imagesf\dimen@ii\divide\dimen@ii by 5}

\catcode`\@=12

\endinput




