# MikTex error for PNG images when trying to produce DVI

I have a tex file with \includegraphic elements for some PNG images. I use MikTeX on Windows and the PDF is fine.

Now, I need a DVI so I tried using: \pdfoutput=0 This creates a DVI, but only after I remove all the PNG images… Otherwise I get errors like:

! LaTeX Error: Cannot determine size of graphic in math-box-plot.png (no BoundingBox).
-
You should also consider compiling to PDF rather than DVI. –  Juan A. Navarro Feb 16 '11 at 10:06
I converted the PNG files to EPS and used those in includegraphics and it works. –  Hagai Cibulski Feb 18 '11 at 9:17

TeX is text based, it cannot determine the size of PNG image itself by default.

A quick solution:

\usepackage{bmpsize}

And use

\usepackage[dvipdfmx]{graphicx}

It is better to use extractbb (also named ebb, xbb) program to produce .bb or .xbb file for LaTeX. Use this command in 'Command Prompt':

for %i in (*.png) do xbb %i

(or for %i in (*.png) do extractbb -x %i, I'm not sure about MiKTeX.)

And use

\usepackage[dvipdfmx]{graphicx}

(I use TeX Live, only dvipdfmx supports png images. But MiKTeX seems different, I can't remember well.)

-
Leo, you better use <code> ... </code> blocks for the command line and similar text to avoid the TeX syntax highlighter. –  Martin Scharrer Feb 16 '11 at 8:41
@Martin: I did not realise that the two were handled differently –  Joseph Wright Feb 16 '11 at 9:28
@Joseph: The syntax highlighting is done in <pre class="prettyprint lang-tex"> tags around <code>. Therefore single <code> tags on their own are not highlighted. –  Martin Scharrer Feb 16 '11 at 9:36

Install the program ImageMagick, then you can do it on the fly:

\documentclass{article}

\usepackage[dvips]{graphicx}
\DeclareGraphicsRule{.png}{eps}{.bb}{convert #1 eps:-}
\DeclareGraphicsRule{.gif}{eps}{.bb}{convert #1 eps:-}
\usepackage{grfext}
\AppendGraphicsExtensions*{.png,.gif}
\usepackage{bmpsize}

\makeatletter
\newcommand*{\IncludeGraphics}[2][]{%
\begingroup
\let\@found\@empty
\@for\@type:=\bmpsize@types\do{%
\ifx\@found\@empty
\ifbmpsize@ok
\let\@found=\@type
\fi
\fi
}%
\ifx\@found\@empty
\includegraphics[{#1}]{#2}%
\else
\includegraphics[{natwidth=\bmpsize@width,natheight=\bmpsize@height,#1}]{#2}%
\fi
\endgroup
}
\makeatother

\begin{document}
\IncludeGraphics{knuth-tex}  % a gif image
\end{document}

btw: you do not need the \pdfoutput=0 simply run latex instead of pdflatex

-
It may be too tricky for new TeXers, with no actual advantage. BTW, ImageMagick may be overkill, bmeps is enough. –  Leo Liu Feb 16 '11 at 11:34
no, it isn't, and ImagaMagick can be used for any other conversion, hence it is no overkill. –  Herbert Feb 16 '11 at 12:07