I'm trying to include graphics in my Latex-file, which I compiled with latex+dvipdf on OS X. Latex however returns this error: "Cannot determine size of graphic"

My graphic is exported from PowerPoint, so I have tried both .pdf and .png. I get the same errors for both.

Sample code that doesn't work:

\begin{figure}[htb]
\begin{center}
\leavevmode
\includegraphics[width=0.8\textwidth]{graph.png}
\end{center}
\end{figure}

If I have to manually set some measurements of the image, please tell me how I can find out those measurements. I need the image to take up about 80% of text width and be centered. Thanks.

up vote 128 down vote accepted

The DVI producing latex doesn't support reading the size of PNG, JPG or PDF images. You need to use pdflatex for this. Actually latex is pdflatex in DVI mode in modern distributions, but it can read the sizes only in PDF mode for some reason. You are however able to state the natural size of the images using natwidth and natheight which will make latex compile without error. The produced DVI file will only link to the PDF and the DVI-to-PDF converter will need to include it in the final PDF. AFAIK dvpdf doesn't support this but dvipdfm does.

\documentclass{article}

\usepackage{graphicx}

\begin{document}
\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth,natwidth=610,natheight=642]{tiger.pdf}
\end{figure}
\end{document}

Compile with either

pdflatex <file base>

or

latex <file base>
dvipdfm <file base>
  • 3
    For dvipdfm(x), one should use dvipdfm or dvipdfmx option of graphicx pacakge, and use extractbb (ebb, xbb) program to produce .bb or .xbb file. bmpsize package can also used to replace extractbb. – Leo Liu May 8 '11 at 15:15
  • 6
    Thank you for the solution provided. I simply added \usepackage[dvipdfm]{graphicx} \usepackage{bmpsize} to my file, and it worked perfectly ! No need to spend time to manually set the bounding box with the time-consuming trial-and-errors method (what I did until this day). – user41288 Nov 19 '13 at 15:17
  • I used this solution for a png-figure with latex, dvipdfmx and graphicx-package, which worked for me without doing anything additional (2013 TeX Live) – Bernhard Jul 3 '14 at 12:09
  • 2
    user41288 solution is great, but there is a typo in the provided code (dvipdfmx). The following one worked for me: \usepackage[dvipdfmx]{graphicx} \usepackage{bmpsize} – zeroos May 12 '15 at 20:56
  • Just to add: specificying natwidth and natheight also solved a problem I had with jpgs having incorrect bounding boxes (so the tex file compiles, but the image ends up misplaced). – Matthew Leingang Nov 5 '15 at 1:10

A non-Latex solution

A very fast solution is to convert the png file into eps format. It can be done easily using graphic software, for instance Inkscape.

So, you only need to open the file in Inkscape and then SaveAs and select eps format.

Now change the extension in the tex file from

\includegraphics[width=0.8\textwidth]{tiger.png}

to

\includegraphics[width=0.8\textwidth]{tiger.eps}
  • 5
    excellent and simple solution. I'd add using command-line convert tiger.jpg eps2:tiger.eps for another easy & easily scriptable way of converting images, as proposed in this answer: stackoverflow.com/a/14220700/3551299 – tlegutko May 15 '17 at 21:52
  • 1
    Nice! I used gimp to convert from .png to .eps gimp.org – wordsforthewise Jul 24 '17 at 21:48
  • Perfect! I used gimp! – Sergio Sep 30 '17 at 5:01
  • png also doesnt work – 41041729 Aug 12 at 16:37

I got this error with a pdf file which contained dots in the filename. Removing the dots (except the .pdf, of course) fixed the issue.

  • 2
    +1 Your answer solved a problem I had been fighting with for 20+ minutes. – evanb Jun 10 '17 at 17:05
  • yep, here, too. Is there an open bug report about it anywhere? – Frederick Nord Apr 13 at 14:02
  • how true it is! very unlikely widely used programs like gimp or inkscape randomly produce wrong images what (Xe)LaTeX can not process. indeed the dot was the reason. – deeenes Oct 15 at 3:43

I saw this issue with a jpeg file. By changing its extension from .JPG to .jpg (yes, just capital to lower) the error went away.

$ pdflatex --version
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) restricted \write18 enabled.

protected by Community Dec 2 '14 at 13:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?