21

I have PNG image I want to introduce into my presentation. The figure is black and white and the edges are small. When I compile the file in pdflatex everything is fine but when I Compile it with xelatex I get !dimension too large error:

[1] <use  "./figs/surface.png" > [2]
! Dimension too large.
<to be read again> 
                   b
l.31 \end{frame}

The line I use:

  \includegraphics<2> [width=0.8\textwidth]{./figs/surface.png}\par

And the file:enter image description here

Here is a MWE:

\documentclass[bigger]{beamer}
\begin{document}

\begin{frame}{Coarse-Grained (CG) simulation of a membrane}
  \begin{columns}
    \begin{column}{0.6\textwidth}
      \includegraphics<2> [width=0.8\textwidth]{./figs/surface.png}\par
      \includegraphics<3> [width=1.0\textwidth]{./figs/a_lipid_CG.jpg}
    \end{column}
    \begin{column}{0.4\textwidth}
      \begin{itemize}
        \item bla
      \end{itemize}
    \end{column}
  \end{columns}
\end{frame}


\end{document}

Here are links to the used files: http://www.4shared.com/photo/EK4CPOF2/a_lipid_CG.html http://www.4shared.com/photo/un7JtzXa/surface.html

Yotam
  • 7,109
  • Make a complete example that demonstrates your error (I have a lot doubts that really the graphics itself is the problem) – Ulrike Fischer Apr 08 '12 at 11:19
  • Using your image in both places I don't get any error. – egreg Apr 08 '12 at 12:50
  • A complete example should start with \documentclass. And make sure that you make the real graphic available. – Ulrike Fischer Apr 08 '12 at 13:36
  • @UlrikeFischer: The file I have uploaded (surface.png) is the one that I use. Do you think it is the other file (a_lipid_CG.jpg) that cause the error? – Yotam Apr 08 '12 at 13:48
  • @egreg: What do you mean ''both places''? – Yotam Apr 08 '12 at 13:50
  • I mean "for both \includegraphics" – egreg Apr 08 '12 at 13:51
  • @egreg: did you try with the bigger option? – Yotam Apr 08 '12 at 13:57
  • Yes, I did; it doesn't seem to change much. – egreg Apr 08 '12 at 14:06
  • @Yotam: Upload scripts can change a picture, e.g. resize it. So better but both pictures in a zip-file somewhere for download. – Ulrike Fischer Apr 08 '12 at 14:16
  • 1
    @Yotam The error message makes it clear that the image ./figs/surface.png has been successively included and even shipped out (on page [2]). So the error must come later. – Stephan Lehmke Apr 10 '12 at 08:40
  • @StephanLehmke: Thanks. I understand what you mean. Still, the pasted code produce an error (running xelatex) which I don't know how to solve. – Yotam Apr 10 '12 at 08:45
  • 1
    The a_lipid_CG.jpg seems to cause the issue. I get the same error with \documentclass{beamer} \begin{document} \begin{frame} \includegraphics{a_lipid_CG.jpg} \end{frame} \end{document}. Note that the [1] <use "./figs/surface.png" > [2] is not part of the error message, but only a info message printed before it. – Martin Scharrer Apr 10 '12 at 08:51
  • Possible duplicate of https://tex.stackexchange.com/questions/243753/is-it-imagemagicks-fault-or-pdflatexs-that-some-jpegs-arent-working which has the technical details in the answers: The image file is missing a JFIF header with ResolutionUnit, XResolution and YResolution. – caw Dec 03 '19 at 00:54

2 Answers2

22

The a_lipid_CG.jpg seems to cause the issue. As explained below this specific JPG seems to be incompatible with XeTeX.

I get the same error with the following MWE:

\documentclass{beamer}
\begin{document}
\begin{frame}
\includegraphics{a_lipid_CG.jpg}
\end{frame}
\end{document}.

Note that the [1] <use "./figs/surface.png" > [2] is not part of the error message, but only a info message printed before it.

After running the JPG image through the conversion tool of Image Magick convert, i.e. convert a_lipid_CG.jpg a_lipid_CG2.jpg and testing the document with this new JPG file, the error disappears. This leads me to the conclusion that your particular JPG file is not fully compatible with XeTeX. Apparently XeTeX has issues reading the size from the meta-data from the JPG, which somehow leads to the "too-large" error.

To fix this please open the JPG file in an image manipulation program and save it again.

Martin Scharrer
  • 262,582
  • As an aside, I know that pdftex has issues with some JFIF headers, resulting in wrong resolution info and thus wrong image dimensions. For instance, it may be that the image has 300dpi, but pdftex doesn't get this info and assumes 72dpi, resulting in scaling the image too large. AFAIK, the source of the error lies in the xpdf library used by pdftex for image inclusion. There could also be issues with included thumbnails, i.e. the dimensions of the thumbnail are reported, but the whole image is output. Correct me if I'm wrong, this isn't really my area of expertise. – Stephan Lehmke Apr 10 '12 at 09:40
  • 2
    I had to convert mine to a png to solve the problem. Very weird bug. – Meekohi Dec 16 '14 at 18:39
  • Saving as PNG works for me too, using GIMP. – Yan King Yin Dec 11 '15 at 12:04
14

Similarly to what @Martin-Scharrer said, convert/mogrify worked for me too, but only by explicitly adding a resolution, which seemed to have been missing. So the following fixed the problem (the files had been produced with matplotlib, btw):

mogrify -density 90 myfile.png
quazgar
  • 1,273
  • 1
    Thank you, this did for me too. Without specifying a resolution, it wouldn't go. – Nikos Alexandris Nov 18 '14 at 11:04
  • Worked for me without resolution, although I was resizing which I wanted to do for other reasons: convert picture.jpg -resize 50% picture.png. I hoped that converting back to JPG using ImageMagic convert will give me a valid JPG, but it did not. However, JPG in general works for me with pdflatex. – wenzeslaus Jun 30 '15 at 03:05
  • I just had a similar issue, and your mogrify trick worked for me on an image not generated by matplotlib, thanks a lot! – lehalle Sep 14 '16 at 07:49