# \includegraphics clipping and trim is squishing image

Clipping keeps squishing my image.

My command is:

\includegraphics[keepaspectratio=false,clip=true,trim=90px 0 0 0]{blue.jpg}


But I'm getting:

Where the original image is:

Why can't I clip or trim an image without squishing? There is a part of an image that I want to cut off without having to go into a photo editor to do it.

-
Does the top answer here help at all? –  Scott H. Aug 21 '12 at 18:15
If you don't want that the image is distorted, why do you set keepaspectratio to false? –  Ulrike Fischer Aug 21 '12 at 18:28
Because aspect ratio refers to width/height. The aspect ratio of the clipped image will be smaller since I reduced the width. –  bobobobo Aug 21 '12 at 18:39
Clipping should work, but @Ulrike is right, keepaspectratio is not needed here and should not be used. Also note that the px unit is a pdftex extension and uses a fixed (but configurable) density which might not be correct for this particular JPG. Sometimes the images metadata are not fully correct, leading to a wrong display with LaTeX. –  Martin Scharrer Aug 21 '12 at 18:50
Well imho the key should either be not necessary or have the value true. But why do you use the key at all? Do you set the width and height key globally? –  Ulrike Fischer Aug 21 '12 at 18:54
show 1 more comment

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 the width and height are specified. Thus the setting and values of keepaspectratio does not matter here.

There is a solution for dvips.def, dvipdfm.def and dvipdfmx.def if pdfTeX is used as TeX compiler (for DVI mode). Package bmpsize fixes as side effect the defective drivers. And the package improves the bitmap inclusion making separate bounding box files obsolete. The driver xetex.def cannot be fixed this way, because XeTeX misses primitives from pdfTeX (especially \pdffiledump), needed by bmpsize.

\usepackage[dvipdfm]{graphicx}
\usepackage{bmpsize}

-
Is there any way these issues can be fixed in the drivers themselves? For example, it's possible to do clipping for XeTeX not at the engine level but using the xdvipdfmx driver. [This also reminds me that I guess I should write some LaTeX3 driver code for picture importing :-)] –  Joseph Wright Aug 21 '12 at 21:22
Clipping can be done via page operators or form xobjects. Someone has written clipping support for xetex.def and posted it to comp.text.tex, but I do not know the current state. The drivers seems not to be actively maintained. –  Heiko Oberdiek Aug 21 '12 at 21:58
'Someone' in the context of xetex.def would be me, with some prodding from Martin Scharrer :-) I was under the impression that you were in charge of the driver code, hence asking. Obviously I was mistaken. –  Joseph Wright Aug 21 '12 at 22:00
I am maintaining pdftex.def. Could you contact the maintainers of xetex.def? –  Heiko Oberdiek Aug 21 '12 at 22:26