16

MWE

Please use the image linked to below.

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\includegraphics{dank}
\end{document}

Oddly enough, only this picture fails and only when compiling with XeTeX (as opposed to pdfTeX or LuaTeX):

ERROR: Dimension too large.

--- TeX said ---
<to be read again> 
                   b
l.5 \includegraphics{dank}

--- HELP ---
From the .log file...

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

The dank meme itself is a bit of an eyesore, so I'm not displaying it inline. Please check the shasum to make sure it's still the same file when you download it.

$ shasum dank.jpg
b889bc28b2ccd079073267159db0562f45b58e4d  dank.jpg

What's special about this image? Why does it fail? Its natural setting (as seen with LuaTeX or pdfTeX) is well under 19 feet.

Sean Allred
  • 27,421
  • Related: http://tex.stackexchange.com/q/51164/24974 – erik Oct 16 '15 at 01:07
  • Can I ask what context prompted dank memes in LaTeX? This question's title took me completely by surprise. – Arun Debray Oct 16 '15 at 03:00
  • @ArunDebray I'm helping someone clean up and improve a LaTeX guide and, alas, it had this dank meme. – Sean Allred Oct 16 '15 at 03:01
  • @SeanAllred Ah, thanks! Well, if erik's suggestion doesn't work for you, you have a wonderful excuse to substitute a different picture... – Arun Debray Oct 16 '15 at 03:02
  • @ArunDebray I know that changing/re-saving/etc. the picture will allow me to continue – I'm more interested in what's stumped XeTeX in the first place ;) – Sean Allred Oct 16 '15 at 03:23
  • A combination of no preferred width in the \includegraphics command and an image with a wildly off-base DPI setting, maybe even as low as 1 DPI? – Mike Renfro Oct 16 '15 at 03:33
  • @MikeRenfro You can set any width you'd like (e.g. [width=1cm]) – no change. How are you getting the DPI information? – Sean Allred Oct 16 '15 at 03:48
  • Beside it is too wide at scale=1, there are something wrong in the JPG format, that for some reason only is a problem for xetex. If you edit this file with The Gimp an then save it without changes with quality 100%, the problem disappear. – Fran Oct 16 '15 at 06:41
  • I didn't get any dpi information myself. Just made a guess. Should be able to get it from any decent image viewer (IrfanView: Image / Info; Preview: Command-I, etc.). Are you saying the dpi info was something sensible? – Mike Renfro Oct 16 '15 at 11:19

1 Answers1

17

The reason is that dank.jpg does not have JFIF, or Exif header. So jpeg driver of XeTeX cannot read density and assumes that it is 1DPI. Thus it becomes very large. The jpeg driver of pdftex also cannot read the density, so assumes it is 72DPI. Solution: Use convert in ImageMagick to add JFIF header.

convert -density 72x72 dank.jpg dank1.jpg

Then converted dank1.jpg will be OK for XeTeX.


To determine if this is the problem with a given image, use (copied from @egreg's comment): identify -verbose dank.jpg | grep Resolution.

Sean Allred
  • 27,421
Akira Kakuto
  • 2,652
  • How did you determine that it didn't have the appropriate headers, though? – Sean Allred Oct 16 '15 at 13:13
  • 1
    @SeanAllred With identify -verbose dank.jpg|grep Resolution you get no information, but you get Resolution: 72x72 for dank1.jpg – egreg Oct 16 '15 at 15:21