3

resolution is undefined in XeTeX so the following code will produce different values when compiled with pdfTeX and XeTeX.

\documentclass{article}
\usepackage{graphicx}

\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=1]{koala.jpg}}

\begin{document}
\the\wd\IBox
\end{document}

How to force pdfTeX and XeTeX to produce the same measurement for the imported image?

13
  • 3
    'Convert the image to a PDF' seems to be the most obvious answer. I'm afraid that XeTeX and pdfTeX are going to be different at a low-level due to the difference in drivers (assuming we are talking about pdfTeX in PDF mode, of course).
    – Joseph Wright
    Commented Aug 3, 2011 at 18:29
  • 3
    I get exactly the same value with my test file
    – user2478
    Commented Aug 3, 2011 at 18:41
  • 4
    What do you mean with "resolution is undefined in xetex". What is resolution? Which values are you getting for pdftex? How big are the differences? They simply might be some rounding issues (bp to pt) conversion. Please don't keep asking "doesn't work" questions without details! BTW, scale=1 is useless but simply adds some overhead. Is it part of the problem? If so, state it explicitly, if not it doesn't has anything to do in a MWE. Commented Aug 3, 2011 at 18:52
  • 2
    run identify -verbose and see whether Resolution is set.
    – Caramdir
    Commented Aug 3, 2011 at 19:13
  • 2
    Duplicate of Image from \includegraphics showing in wrong image size? Commented Aug 3, 2011 at 19:27

2 Answers 2

6

tl;dr version: The metadata in the Koala file is inconclusive, as the Exif header exists, but doesn't specify the resolution. To solve the problem use some tool to either add the resolution to the Exif data or remove the Exif data completely.


First some technicalities on how metadata of (modern) jpg images is stored (I'm not an expert on this, so the following might not be entirely correct): There are two formats for metadata, called JFIF (JPEG file interchange format) and EXIF (Exchangeable image file format). The first was created to solve some deficiencies with the original JPEG file format (JIF), the second one to add metadate from cameras. Both can be present in the same file (and usually are). Both have a field to set the resolution of the image. Note that the original JPEG file format (JIF) had no way of storing the resolution.

The Koala.jpg image that comes with Windows includes both kinds of metadata (though most Exif fields are unused). However it only has the resoltution stored in the JFIF metadata, while the Exif resolution field is empty. It seems that pdflatex and xelatex behave differently in this setting.

  • pdflatex either always ignors the Exif data or falls back to the JFIF data when the Exif data it is incomplete. So it successfully reads the resolution information from the file and applies it. (I guess Taco's solution attempts only set the default resolution and hence where overridden by the successfully read resolution from the file.)
  • xelatex sees the Exif metadata and thus tries to read from it. But since there is no resolution information in it, it falls back to its default resolution of 72ppi. It seems that when some Exif data is present, xelatex ignores the entire JFIF block (I don't know whether this is a feature or a bug). When the Exif data is completely removed (e.g. via exiv2 rm Koala.jpg), then it reads the JFIF metadata and correctly applies the resolution stored there.
1
  • I removed my answer and others might get confused with the koala's bad story. Commented Aug 3, 2011 at 23:38
2

Looks like the image does not have any actual resolution information, and that xetex and pdftex use different defaults.

To elaborate: I think this the case, because pdftex appears to be using 96dpi, which matches its idea of what a pixel resolution is. It follows that I expect that the 72dpi that identify reports is not actually inside the jpg file, but just a default that it uses.

4
  • @xport: too bad. I could not test it... Commented Aug 3, 2011 at 19:40
  • @Taco: That doesn't do anything either.
    – Caramdir
    Commented Aug 3, 2011 at 20:40
  • I removed the non-working 'solutions' from my answer, but I still think the remaining text is correct. Commented Aug 3, 2011 at 20:52
  • I think I know why your solutions didn't work (see my answer).
    – Caramdir
    Commented Aug 3, 2011 at 22:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .