pdftex in dvi mode and reading JPEG files
Hi, I have always found annoying that pdftex and latex don't accept the same formats of image files (jpg,png,pdf versus eps). It doesn't really make sense, as including a JPEG into a postscript file is a very easy operation since postscript 2.0. It annoys me so much that I am trying to change that. So far, I have written a patch for dvips (the version in the texlive) which makes dvips able to read and embed JPEG files into a postscript. The next step is adding LaTeX support. As it stands, one can use my patched dvips with a LaTeX file looking like ... \usepackage{graphicx} \DeclareGraphicsRule{.jpg}{eps}{}{} ... \includegraphics[bb=0 0 width height]{bla.jpg} ... where width and height are the dimension (in bp) of bla.jpg. It works, but it is not very ergonomic. It would be much nicer if LaTeX were able to read by itself the size of the picture. It should be very easy to do, as in modern TeX distributions, latex is simply pdfetex working in dvi mode, and pdfetex knows how to read jpg files. I tried to print the size of my picture with the following LaTeX code {\setbox0=\hbox{\pdfximage{bla.jpg}\pdfrefximage\pdflastximage} \the\wd0\the\ht0} but it doesn't work in dvi mode, as the executable complains that I dared to use pdfximage in dvi mode, and exits. It seems to me, however, that the previous code should be allowed in dvi mode, as nothing weird for a dvi file arrives on the output list. In other words, I suggest that \pdfximage should be allowed a priori in dvi mode, and that an error should only occur if the program actually tries to write the image on the output file. In that way, it would become possible to patch the graphics package in order to include JPEG files in dvi mode and produce a valid postscript file with my patched dvips. Another possibility, of course, would be to introduce one or two new primitives in pdfetex which would give the size of a picture file. What do you think ? Is either of my suggestions acceptable ? My patch is available on http://tudia.nerim.net/tex/ Thanks, Éric Brunet
On Wed, Oct 25, 2006 at 01:21:40PM +0200, Eric.Brunet@lps.ens.fr wrote:
I have always found annoying that pdftex and latex don't accept the same formats of image files (jpg,png,pdf versus eps). It doesn't really make sense, as including a JPEG into a postscript file is a very easy operation since postscript 2.0.
But there are lots of different drivers: dvips, dvipsone, VTeX, ... The main problem is a missing standard for graphics inclusion and other things that extends the DVI format specification.
It annoys me so much that I am trying to change that. So far, I have written a patch for dvips (the version in the texlive) which makes dvips able to read and embed JPEG files into a postscript.
There is no need to patch, dvips already can convert and embed files on the fly. (See the last argument of \DeclareGraphicsRule, check dvips (configuration) options for enabling the feature, if it is disabled.)
The next step is adding LaTeX support. As it stands, one can use my patched dvips with a LaTeX file looking like ... \usepackage{graphicx} \DeclareGraphicsRule{.jpg}{eps}{}{} ... \includegraphics[bb=0 0 width height]{bla.jpg} ... where width and height are the dimension (in bp) of bla.jpg.
No need for this, look at package bmpsize!
It works, but it is not very ergonomic. It would be much nicer if LaTeX were able to read by itself the size of the picture.
pdfTeX >= 1.30 and package bmpsize.
Yours sincerely
Heiko
Eric.Brunet@lps.ens.fr wrote:
Another possibility, of course, would be to introduce one or two new primitives in pdfetex which would give the size of a picture file.
this has also been discussed with the author of dvipdfmx (chof) during tug 2005 in wuhan; there we've put it on Hartmuts plate -) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi, Thank you for your answer,
Heiko Oberdiek Wrote:
I have always found annoying that pdftex and latex don't accept the same formats of image files (jpg,png,pdf versus eps). It doesn't really make
But there are lots of different drivers: dvips, dvipsone, VTeX, ... The main problem is a missing standard for graphics inclusion and other things that extends the DVI format specification.
I agree, doing things perfectly is a huge task. But, hey, one needs to start somewhere. Having dvips working would already be something...
There is no need to patch, dvips already can convert and embed files on the fly. (See the last argument of \DeclareGraphicsRule, check dvips (configuration) options for enabling the feature, if it is disabled.)
Well, solutions such as \DeclareGraphicsRule{.jpg}{eps}{}{`jpeg2ps -r0 #1} are not really satisfactory: even if your correspondants use the same driver as you do, they need to have an extra program installed, and they need to have a very unsecure option enabled. (Do you really like the idea that ``latex foobar && dvips foobar -o'' might erase all your files if foobar was written with bad intentions ?) The most important problem is that if you want to be compatible with what pdflatex does wehn including a jpeg file without specifying its size, you need to invoke ``jpeg2ps -r0'' for jpg files with a resolution in the JFIF segment, and ``jpeg2ps -r72'' for jpg files without a resolution, so you cannot have everything working correctly with a simple \DeclareGraphicsRule invocation. That is very annoying ! Is there a better programm than jpeg2ps out there ? Of course, my patch simply does the same thing as jpeg2ps from within dvips, but without the senseless rescaling. The only difference is that it is more robust (no problem fiddling with the options of jpeg2ps), and no need for the unsecure shell-escapes.
No need for this, look at package bmpsize!
That is great. I didn't know that wonderfull package. Unfortunately, I cannot test it right now because my pdftex is too old, but I'll remember it exists. Thanks ! Éric Brunet
On Wed, Oct 25, 2006 at 04:27:12PM +0200, Eric.Brunet@lps.ens.fr wrote:
Heiko Oberdiek Wrote:
I have always found annoying that pdftex and latex don't accept the same formats of image files (jpg,png,pdf versus eps). It doesn't really make
But there are lots of different drivers: dvips, dvipsone, VTeX, ... The main problem is a missing standard for graphics inclusion and other things that extends the DVI format specification.
I agree, doing things perfectly is a huge task. But, hey, one needs to start somewhere. Having dvips working would already be something...
There is no need to patch, dvips already can convert and embed files on the fly. (See the last argument of \DeclareGraphicsRule, check dvips (configuration) options for enabling the feature, if it is disabled.)
Well, solutions such as \DeclareGraphicsRule{.jpg}{eps}{}{`jpeg2ps -r0 #1} are not really satisfactory: even if your correspondants use the same driver as you do, they need to have an extra program installed,
Otherwise you would need uptodate programs, that is also a problem, see below.
and they need to have a very unsecure option enabled. (Do you really like the idea that ``latex foobar && dvips foobar -o'' might erase all your files if foobar was written with bad intentions ?)
The insecure option can be avoided by a small dvi filter program. It analyzes the \special texts, performs secure conversions and replaces the conversion commands in the \special text by the converted output file.
The most important problem is that if you want to be compatible with what pdflatex does wehn including a jpeg file without specifying its size, you need to invoke ``jpeg2ps -r0'' for jpg files with a resolution in the JFIF segment, and ``jpeg2ps -r72'' for jpg files without a resolution, so you cannot have everything working correctly with a simple \DeclareGraphicsRule invocation. That is very annoying ! Is there a better programm than jpeg2ps out there ?
You can inspect the resolution using bmpsize.
Of course, my patch simply does the same thing as jpeg2ps from within dvips, but without the senseless rescaling. The only difference is that it is more robust (no problem fiddling with the options of jpeg2ps), and no need for the unsecure shell-escapes.
There are lots of image formats (n): BMP, GIF, JPEG, MSP, PAM, PCX, PNG, PNM, SGI, TGA, TIFF, WMF, XPM, ... And there are lots of dvi drivers (m): dvips, dvipsone, dvipdfm, pdfTeX, VTeX, ... Thus the work is O(n \times m), I would prefer a solution with O(n + m).
No need for this, look at package bmpsize!
That is great. I didn't know that wonderfull package. Unfortunately, I cannot test it right now because my pdftex is too old, but I'll remember it exists.
It uses \pdffiledump, available since pdfTeX 1.30.
Yours sincerely
Heiko
participants (3)
-
Eric.Brunet@lps.ens.fr
-
Hans Hagen
-
Heiko Oberdiek