2

Somehow Photoshop seems to save JPGs that causes XeLaTeX some issues. Images that are saved by my colleague from Photoshop cause the error:

! Dimension too large. <to be read again>

If I run imagemagik convert over the image (retaining the dimensions) then XeLaTeX will compile OK.

pdflatex seems to be able to compile without error

\documentclass[10pt]{report}

\usepackage{graphicx}


\begin{document}

\includegraphics{peruvian.jpg}
\includegraphics{peruvian-converted.jpg}
% converted with: convert peruvian.jpg  peruvian-converted.jpg
\end{document}

files have the same dimensions:

$ file peruvian.jpg peruvian-converted.jpg 
peruvian.jpg:           JPEG image data, baseline, precision 8, 1196x500, frames 3
peruvian-converted.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1196x500, frames 3

the image can be downloaded here. I gzipped it to avoid Dropbox messing with the image.

I'm running xelatex on Debian Stretch, texlive-xetex version: 2016.20170123-5

I know I could run convert over each image before I use it but I'd rather know why this happens and find a way to not have to convert images before I use them.

  • For peruvian.jpg, I obtain similar results for pdflatex and xelatex in the TeX Live 2018: In pdflatex, Overfull \hbox (828.1069pt too wide). In xelatex, Overfull \hbox (828.48207pt too wide). – Akira Kakuto Oct 05 '18 at 09:17
  • Thanks. I'll give TeX Live 2018 a go, but I was hoping for a solution that would work with the version of TeX installed in debian stretch. – Jason Lewis Oct 07 '18 at 23:23
  • I can confirm it does work in TL2018 – Jason Lewis Oct 08 '18 at 00:04
  • 1
    related to https://tex.stackexchange.com/questions/51164/dimension-too-large-on-a-png-figure-under-xelatex-and-beamer – Jason Lewis Oct 08 '18 at 03:08
  • Also related: https://tex.stackexchange.com/questions/243753/is-it-imagemagicks-fault-or-pdflatexs-that-some-jpegs-arent-working – caw Dec 03 '19 at 00:56

1 Answers1

2

The reason is that the dimensions DPI are not set. They can be set to anything, but if not set at all this is what you get.

You need to "fix" the file without degrading the image (for example loading and saving the jpg using other software may work, but is a bad idea). What is needed is to add the appropriate metadata to the file. Imagemagik convert is not lossless and does much more than just fix the missing header.

Several image software packages do not set this properly as it is rarely used (but LaTex can use it under some circumstances -- see below), but for some odd reason TeX requires it to be set (to anything you like - because it is not used - whether you choose 100x100 or 400x400 you will get the same LaTeX output). Unless, that is, you include images at their native resolution without specifying dimensions as in

\includegraphics{peruvian.jpg}

It is called the JFIF header which actually doesn't need to exist in JPEG anyway.

One way to add the header is using ExifTool (available on various platforms). These are the command line arguments to exiftool:

-jfif:Xresolution=300  -jfif:Yresolution=300  -jfif:ResolutionUnit=inches

So

exiftool peruvian.jpeg -jfif:Xresolution=300  -jfif:Yresolution=300  -jfif:ResolutionUnit=inches

This zip contains the original and the fixed version of your jpeg (link won't stay live forever though). Try it out.

https://www.dropbox.com/s/4dsx8kfbay4rc8u/peruvian.zip?dl=0

As an aside -- yes, some versions of Photoshop and other software do not produce compliant jpeg headers. See for example: https://feedback.photoshop.com/photoshop_family/topics/jpeg_format_different_between_cs2_and_cs6