[texhax] Using .png, .jpg, .gif

Uwe Lück uwe.lueck at web.de
Tue Aug 4 21:59:32 CEST 2009


Hi,

----- At 05:43 02.07.09, Beverley Eyre wrote: -----
 > I've been playing with the graphicx package trying to figure out
 > how to easily use non-postscript images in a latex doc.
 > I know that I could use pdflatex, but then I'd have the inverse problem.

(There was

     http://tug.org/mailman/htdig/texhax/2009-July/012860.html

on this list on this theme.)

 > I want a universal solution.
 >
 > I'd like to get \DeclareGraphicsRule to work, but it seems more trouble
 > to use than just converting each image file by hand.
 >
 > For example, if I want to use a .png file:
 > \DeclareGraphicsExtensions{.png, .eps}
 > \DeclareGraphicsRule{.png}{eps}{*}{`convert #1}
 > %% (the last arg I've done in many different ways, e.g. {`convert #1 
eps:- } )
 >
 > then, in the body:
 >
 > \includegraphics[width=1in]{myimage} %% (which is myimage.png)

If it were that simple, namely the method to read .eps worked as well with 
.jpg etc., this would have been provided by the graphics bundle for more 
than 10 years. It is not -- of course. LaTeX can read the dimensions from 
an .eps because this information is contained in an .eps as a plain text 
line -- in those other files such information is encrypted in a binary way. 
Extracting it using "ordinary" TeX would require emulating real graphics 
software by TeX macros. This might (I am still not perfectly informed, 
please correct me) include emulating unzip by TeX macros -- an idea I like 
much; but there is an essential limitation: TeX's buffer size. There is a 
chance that the graphics file is too large and has too few "endline" bytes 
to be bitable for TeX.

I have now collected some relevant things from the UK TeX FAQ (searched for 
`png' and `jpg'). While in a parallel thread epstopdf and using PDFLaTeX 
rather than "ordinary" LaTeX was recommended, one may still prefer 
"ordinary" LaTeX, perhaps because one's DVI viewer shows the page one is 
editing more reliably than your PDF viewer (cf. pdfsync package). There are 
some nice extensions to the graphics bundle:

1. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=dvipsgraphics

-- some tools converting to eps, general: ImageQuick's `convert', cf.

     http://www.imagemagick.org/script/command-line-processing.php

(Was mentioned in the original posting, included here for other readers.)

2. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=dvipdfmgraphics

-- a utility ebb extracting bounding boxes! -- part of dvipdfm package, cf. 
p. 20 of

     http://tug.ctan.org/tex-archive/dviware/dvipdfm/dvipdfm.pdf

\par May be related, too:

3. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn

4. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=pdftexgraphics

HTH -- Uwe L.


----- Originalnachricht -----
Gesendet: 2009/07/02 05:43:28
Betreff: [texhax] Using .png, .jpg, .gif

Hi all.

I've been playing with the graphicx package trying to figure out how to 
easily use non-postscript images in a latex doc. I know that I could use 
pdflatex, but then I'd have the inverse problem. I want a universal solution.

I'd like to get \DeclareGraphicsRule to work, but it seems more trouble to 
use than just converting each image file by hand.

For example, if I want to use a .png file:
\DeclareGraphicsExtensions{.png, .eps}
\DeclareGraphicsRule{.png}{eps}{*}{`convert #1} %% (the last arg I've done 
in many different ways, e.g. {`convert #1 eps:- } )

then, in the body:

\includegraphics[width=1in]{myimage} %% (which is myimage.png)

I get an error msg telling me that I there is no bounding box. So in order 
to use it, I have to determine the bounding box for the image first, and 
then include that info into one or the other command. But, if I just do:

 > convert myimage.png myimage.eps

on the command line, it converts it without having to know the bounding box 
info. I'm not sure why convert needs the bounding box info in one case 
(latex) but not the other (command line).

So, I'm not really getting the point of \DeclareGraphicsRule since using it 
is much more trouble than converting by hand. Which brings me back to my 
point, is there any easy way to use non-postscript images in a latex doc? 
My best guess at this point is no, and the only way forward is to re-write 
some of the graphicx commands to that they can use the bounding box info 
generated by 'convert' or some other conversion program.

TIA for any help or discussion.

Beverley Eyre



More information about the texhax mailing list