TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
possible duplicate of: tex.stackexchange.com/questions/11193/… (untagged) – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 15 '14 at 20:20
up vote 80 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>
share|improve this answer
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
5  
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
1  
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}
share|improve this answer

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 --verion
pdflatex: unrecognized option '--verion'
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) restricted \write18 enabled.
share|improve this answer

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?