[Tex/LaTex] Anybody ever encountered “arithmetic: number too big” when importing an image


I'm trying to insert an image, which I've done probably a thousand times before, but I'm having issues with this one.

The image is a jpg I just created in Paint – it's not excessively large or high resolution.

enter image description here

The original image is available here.

I'm using the regular ol' \includegraphics command in the graphicx package, and the PDF will compile but the image will not show up and the log file says:

"pdflatex.exe: arithmetic: number too big"

I've tried scaling on the off chance that the picture is too big (which it really isn't – it's 640×480 pixels) but I'm still getting the error.

Here's the relevant code:


After a quick Google search I saw that somebody suggested \pdfimageresolution=72 which seemed to fix the problem for that person, but it isn't working for me. Any suggestions?

Best Answer

I believe your problem is due to the resolution (in dots per inch, not the number of pixels!) stored in the image file. I had the same problem with an image having a ridiculously low resolution (1 dpi or less, displayed as 1 dpi in GIMP). Saving the JPEG image again or recompressing to PNG did not help at all, but setting a reasonable resolution (e.g., 300 dpi) did.

Your image seems to have the same problem:

% file 14345le.jpg
14345le.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 1x1, segment length 16, comment: " Image generated by Aladdin Ghostscript (device=pnmraw)", baseline, precision 8, 640x480, frames 3

Note the "density 1x1" bit. You can see the same information in the GIMP and modify it through the Image → Scale Image dialog box, then export using the File menu to save the modified image. Beware that you will lose quality unless you choose a lossless compression format such as PNG.

I'm not a pdfTeX expert, but I think the origin of the problem is that given enough pixels, a ridiculously low resolution is guaranteed to result in dimensions that exceed \maxdimen, the largest length that TeX can deal with. For instance, with your 640x480 image at 1 dpi, you get a width of (640/1)*72.27 = 46252.8pt, which exceeds \maxdimen = 16383.99999pt (according to https://tex.stackexchange.com/a/430/73317).