# Bad image size on only some images when using bb argument of \includegraphics?

I've had a snippet of code, that I've used (apparently) with tex4ht (which compiles with latex) to obtain an html document - and as far as I can remember (was some time ago) it worked without a problem. Now I try to compile the same snippet with pdflatex, and I have an erroneous image size - but this occurs only at some uses of the bb= (bounding box) parameter.

Apparently, I've needed to add the bb= parameter to avoid having separate bbox files when latex was to process this code, and AFAICR it worked fine. The thing is, I'd like to keep the same code also in the pdflatex compilation run.

For this, I've made a zip containing the original source images:

... and I've managed to reconstruct the error with this MWE:

\documentclass{book}
\usepackage{graphicx}

\begin{document}

\begin{figure}[hbt]
\centering
\includegraphics[bb=0 0 1408 1056,width=0.49\textwidth]{IMG1.JPG}  \includegraphics[width=0.49\textwidth]{IMG2.jpg} %bb=0 0 1629 1221
\ifdefined\ifHtml\HCode{<br/>}\else\fi
\caption{Left: some text here; right: some text there}
\label{fig:fig1}
\end{figure}

\begin{figure}[tb]
\centering
\includegraphics[bb=0 0 1000 1415,width=0.49\textwidth,trim=90 540 250 380,clip]{IMG3} \includegraphics[bb=0 0 1600 1200,width=0.49\textwidth]{IMG4}
\ifdefined\ifHtml\HCode{<br/>}\else\fi
\caption{Left: some text here; right: some text there}
\label{fig:fig2}
\end{figure}

\end{document}


The output is this (click for high res):

This is the problem:

• In the first figure (top two images), whenever I use the bb= parameter to \includegraphics, I get the wrong image size (much smaller than width=0.49\textwidth)
• In the second figure (bottom two images), I use the bb= paramaeter to \includegraphics - and here there is no problem, the size is correct?!

The IMG* images are originally from a camera; I replaced their contents with red fill in Gimp, and resaved - and strangely, the error still occurs; it is these image that are in testpics.zip. So even if the image data itself is gone, EXIF data is still present in these images, and I tried:

exiftool -f IMG*


... but I cannot see anything strange about the first two images, which might cause this error when bb= is used in the first figure. Here is a quick overview of the image sizes:

$identify IMG* IMG1.JPG JPEG 1408x1056 1408x1056+0+0 8-bit DirectClass 13KB 0.010u 0:00.000 IMG2.jpg[1] JPEG 1629x1221 1629x1221+0+0 8-bit DirectClass 16.1KB 0.000u 0:00.000 IMG3.jpg[2] JPEG 1000x1415 1000x1415+0+0 8-bit DirectClass 8.7KB 0.010u 0:00.000 IMG4.JPG[3] JPEG 1600x1200 1600x1200+0+0 8-bit DirectClass 15.6KB 0.000u 0:00.000  But note what pdflatex outputs in the log when compiling: Package pdftex.def Warning: Option bb' does not make sense, (pdftex.def) using viewport' instead on input line 8. <IMG1.JPG, id=1, 565.312pt x 423.984pt> <use IMG1.JPG> <IMG2.jpg, id=2, 654.0435pt x 490.2315pt> <use IMG2.jpg> Package pdftex.def Warning: Option bb' does not make sense, (pdftex.def) using viewport' instead on input line 16. <IMG3.jpg, id=3, 1003.75pt x 1420.30624pt> <use IMG3.jpg> Package pdftex.def Warning: Option bb' does not make sense, (pdftex.def) using viewport' instead on input line 16. <IMG4.JPG, id=5, 1606.0pt x 1204.5pt> <use IMG4.JPG>  So, it sort of "interprets" the first two images to be smaller, but I really don't understand why. Can anyone explain why this happens - and how could I get the code to compile correctly also in pdflatex, while keeping the original code with the bb= parameters in the \includegraphics command? EDIT: Found out why the first two images are intepreted differently - they have a different print size/resolution: $ identify -verbose IMG* | grep 'Image:\|Resolution:\|Print'
Image: IMG1.JPG
Resolution: 180x180
Print size: 7.82222x5.86667
exif:FocalPlaneXResolution: 2816000/225
exif:FocalPlaneYResolution: 2112000/169
exif:XResolution: 180/1
exif:YResolution: 180/1
Image: IMG2.jpg
Resolution: 180x180
Print size: 9.05x6.78333
exif:FocalPlaneXResolution: 2816000/225
exif:FocalPlaneYResolution: 2112000/169
exif:XResolution: 180/1
exif:YResolution: 180/1
Image: IMG3.jpg
Resolution: 72x72
Print size: 13.8889x19.6528
Image: IMG4.JPG
Resolution: 72x72
Print size: 22.2222x16.6667
exif:FocalPlaneXResolution: 1600000/225
exif:FocalPlaneYResolution: 1200000/169
exif:XResolution: 72/1
exif:YResolution: 72/1


So, apparently, those with resolution of 72 dpi have their bb= interpreted correctly, but those that do not have that print resolution (the first two are 180 dpi) have a bad size when bb= is used with pdflatex.

I guess I could just change the DPI print resolution of the images in Gimp and be done with it - but assuming I don't want to change neither the images nor the code, how would I proceed? I tried texdoc graphicx, but it doesn't seem to have a resolution parameter...

If you need bb parameters, you have to give correct values.

\includegraphics[bb=0 0 1408 1056,width=0.49\textwidth]{IMG1.JPG}
\includegraphics[width=0.49\textwidth]{IMG2.jpg} %bb=0 0 1629 1221


should be changed into

\includegraphics[bb=0 0 563 422,width=0.49\textwidth]{IMG1.JPG}
\includegraphics[width=0.49\textwidth]{IMG2.jpg} %bb=0 0 652 488


A command

extractbb IMG1.JPG


may tell you a correct boundingbox in a created IMG1.xbb.