Page 1 of 1

Autocropping: image is shifted

Posted: 2010-04-23T08:36:11-07:00
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

Re: Autocropping: image is shifted

Posted: 2010-04-23T08:44:05-07:00
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.

Re: Autocropping: image is shifted

Posted: 2010-04-23T08:56:20-07:00
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

Re: Autocropping: image is shifted

Posted: 2010-04-23T09:02:44-07:00
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.

Re: Autocropping: image is shifted

Posted: 2010-04-23T12:56:51-07:00
by fdelente
Perfect, problem solved!

Thank you very much for your help!

--
F. Delente