[texhax] using jpg files

Reinhard Kotucha reinhard.kotucha at web.de
Fri Jun 1 01:13:48 CEST 2012


On 2012-05-31 at 11:00:22 -0700, Pierre MacKay wrote:

 > On 05/31/2012 07:11 AM, Walt Burkhard wrote:
 > > Hello,
 > >
 > > I am using TeX (not LaTeX) and need to include a few jpg files.
 > > What tools do we have for this?
 > >
 > >
 > My choice would be to use any tool that would transfer them to EPS
 > format.  Then they could be scaled to fit, using dvips (although
 > often within only narrow limits owing to the inflexibility of
 > bit-map formats) .

Hi Pierre,
just a few remarks.  Scaling itself doesn't have any impact on the
quality of the included graphic.  It's included as is in the output
file and no downsampling takes place.  Modern digital cameras create
large pictures.  Since pdftex assumes 72 dpi by default, the necessary
scaling factor might be huge.  The quality doesn't depend solely on
the scaling factor.  What matters is the resolution of the image and
the resolution of the output device.  The latter is not known in
advance, especially because screen viewers often provide magnifying
glasses.  The best one can do is to provide photographs with a
significantly higher resolution than (presumably) needed and scale
them down accordingly.

The diversion via dvips is not necessary because TeX engines, which
support PDF output directly, offer two ways to scale included graphics.
I'm not confident with xetex, hence the following refers to
pdftex/luatex.

In Phil's example you can see that graphics can be scaled when they
are imported:

	\immediate \pdfximage width 2in {\filename}
	{\pdfrefximage \pdflastximage}

It's also possible to change the transformation matrix temporarily
when \pdfrefximage is executed.  This is necessary if you want to have
a graphic file included only once in your PDF file but want the
graphic to be displayed more than once at different sizes in the
document.  In this case the value of \pdflastximage has to be copied
to a macro immediately after loading the file for later use.

In order to scale each instance, you can use \pdfliteral the same way
you would use \special with dvips.  The PDF operator 'cm' is
aquivalent to 'concat' in PostScript, and 'q/Q' is equivalent to
'gsave/grestore'.

The ability to include a graphic once and use it several times leads
to smaller output files.  I doubt that this can be achieved by
manipulating external EPS files.  Furthermore, the latter requires
manual work or separate scripts or a makefile.  And things can become
arbitrarily complicated if the size of the graphic is supposed to be
relative to \hsize.

It's certainly easier to write a TeX macro for graphics inclusion,
even one which supports all engines.  All engines support \special or
something similar, and PostScript and PDF are quite similar too.
Phil's example is a good starting point.  Experience with PostScript
is very helpful in order to understand the concepts of PDF.

BTW, IMO the best tool which converts bitmap graphics to EPS and PDF
is sam2p.  It's extremely fast and creates much smaller files than any
other tool, without loss of quality.

TeX Live provides sam2p for Windows already.  On Unix, if it's not
part of the distribution, it can be downloaded from

  http://pts.szit.bme.hu/sam2p/

Sorry, but I can't resist to promote sam2p.  It's a pity that most TeX
users aren't aware of it.

Regards,
  Reinhard

-- 
----------------------------------------------------------------------------
Reinhard Kotucha                                      Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                              mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------


More information about the texhax mailing list