Page 1 of 1

unable to crop image

Posted: 2014-01-10T13:34:32-07:00
by jedierikb
I have two 1095x645 png images which load fine in any web browser.

When I run this command on the first image, it crops the image.

Code: Select all

convert img1.png -crop 20.7058823529%x20.8%+59.3129411765+350.88 img1-crop.png
But when I run the same command on the second image, I get an error.

Code: Select all

convert img2.png -crop 20.7058823529%x20.8%+59.3129411765+350.88 img2-crop.png

Code: Select all

convert: geometry does not contain image `ok.png' @ warning/transform.c/CropImage/666.
Searched the forums, and there are suggestions to rebase before cropping, but not sure how that advice applies here.

On Mac running OS10.9.1
Version: ImageMagick 6.8.7-7 Q16 x86_64 2013-11-27 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl png xml zlib

Re: unable to crop image

Posted: 2014-01-10T14:28:04-07:00
by snibgo
You might need to "+repage" before crop. Diagnosis is difficult without the file. You can put it in dropbox.com or similar and paste the URL here.

Re: unable to crop image

Posted: 2014-01-13T07:15:18-07:00
by jedierikb
That was it, thank you. I am guessing that the image file does not have trustworthy sizing information without the repage command?

Re: unable to crop image

Posted: 2014-01-13T07:36:57-07:00
by snibgo
Png files can contain metadata saying the image is at a given offset on a larger canvas. If your crop is within the canvas but not the image, IM warns you. "+repage" removes that metadata.

Re: unable to crop image

Posted: 2014-01-13T07:41:07-07:00
by glennrp
jedierikb wrote:That was it, thank you. I am guessing that the image file does not have trustworthy sizing information without the repage command?
It may contain offset information that puts the image outside of the crop area. Compare the output of "identify img1.png" with "identify img2.png". Then
do "convert img2.png +repage img3.png" and look at "identify img3.png".