(Summarising the comments as an answer.)
pdfTeX will work with px
units, but you have to set these up appropriately using \pdfpxdimen
. This is the physical width of one pixel, and has default value of 1 bp
, meaning that images initially are assumed to be 72 dpi. \pdfpxdimen
is a low-level dimen primitive, and so is best set using \dimexpr
:
\pdfpxdimen=\dimexpr 1 in/<dpi>\relax
where <dpi>
is the resolution of the image.
With that set correctly, you can then use \includegraphics
as normal, adding px
to the values used by the trim
(or other) key to get the right result.
As an example, consider the two images
and
which have the same pixel size but different resolution. Using the LaTeX file
\documentclass{standalone}
\usepackage{graphicx}
\begin{document}
\setlength\fboxsep{0 pt}
\pdfpxdimen=\dimexpr 1 in/600\relax
\includegraphics[clip,trim=0 100px 200px 100px]{Figure-a} % 600 dpi
\pdfpxdimen=\dimexpr 1 in/72\relax
\includegraphics[clip,trim=0 100px 200px 100px,scale = 0.12]{Figure-b} % 72 pdi
\end{document}
results in the output file
which shows the result of the trimming - both are the same. (I've scaled the second image so that the two are printed the same size by pdfTeX.)
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).
Best Answer
It is clearly a bug in the driver for package
graphicx
:pdftex.def
: ok.dvips.def
: ok for PostScript images, but clipping is not supported for bitmap images.xetex.def
: Clipping is not supported at all.dvipdfm.def
: The image is not trimmed, but distorted in the final area.dvipdfmx.def
: The whole image is put in the final area without distortion, but empty space is put above the small image.A remark to
keepaspectratio
: It has a meaning only if both thewidth
andheight
are specified. Thus the setting and values ofkeepaspectratio
does not matter here.There is a solution for
dvips.def
,dvipdfm.def
anddvipdfmx.def
ifpdfTeX
is used as TeX compiler (for DVI mode). Packagebmpsize
fixes as side effect the defective drivers. And the package improves the bitmap inclusion making separate bounding box files obsolete. The driverxetex.def
cannot be fixed this way, because XeTeX misses primitives from pdfTeX (especially\pdffiledump
), needed bybmpsize
.