Autocropping: image is shifted

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
fdelente

Autocropping: image is shifted

Post by fdelente »

Hello.

I'm trying to autocrop PDF geometric pictures that I created with LaTeX.

I used pdftoppm to convert the PDF to a PNG, then 'convert -trim file.png newfile.png' to crop the PNG.

However, the cropped PNG is shifted down to the right, according to identify and to the Gimp:

$ identify newfile.png
ds2-tikz-1.png PNG 1654x2363 4961x7016+279+154 8-bit PseudoClass 256c 41.3kb

How can I avoid this shift automatically? In Gimp, autocrop adjusts the bounding box of the image, is there a similar function with ImageMagick?

Thanks.

--
F. Delente
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Autocropping: image is shifted

Post by fmw42 »

post a link to your image.

It may be that your background is not constant, so you could add -fuzz XX% -trim +repage to allow the trimming to get closer to the part of the image you want to extract and (+repage) to remove any virtual canvas,which may be the problem.
fdelente

Re: Autocropping: image is shifted

Post by fdelente »

> post a link to your image.

The original uncropped image (from a PDF, at 600DPI) http://fdelente.free.fr/original.png.

The image cropped by convert http://fdelente.free.fr/cropped.png.

> It may be that your background is not constant, so you could add -fuzz XX% -trim +repage to allow the trimming to get closer to the part of the image you want to extract and (+repage) to remove any virtual canvas,which may be the problem.

I don't know about the virtual canvas, that maybe the culprit, but for the fuzz part, my background is pure white so I don't think it's the cause.

--
F. Delente
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Autocropping: image is shifted

Post by fmw42 »

your trim has left a virtual canvas around the image, so remove the virtual canvas after trimming

convert original.png -trim +repage cropped.png

see if that does what you want.
fdelente

Re: Autocropping: image is shifted

Post by fdelente »

Perfect, problem solved!

Thank you very much for your help!

--
F. Delente
Post Reply