Page 1 of 1

Cropping bug with tif, png... ImageMagick 6.4.5 to 6.5.7

Posted: 2009-10-23T14:47:42-07:00
by tnetter
With this image:
http://tinyurl.com/TryCropThis-tif
Try doing a:
convert -crop 950x330 TryCropThis.tif Cropped.tif
or even a:
convert -crop 950x330+1+1 TryCropThis.tif Cropped.tif

And you will notice that Cropped.tif is cropped far smaller vertically than specified.
Then try in PNG format:
convert TryCropThis.tif TryCropThis.png
convert -crop 950x330+1+1 TryCropThis.png Cropped.png
Same problem.

However, if you convert instead to JPG, then the crop is correct!
convert TryCropThis.tif TryCropThis.jpg
convert -crop 950x330+1+1 TryCropThis.jpg Cropped.jpg
No problem when using GIF format either.

This was done initially with ImageMagick 6.4.5 provided for Ubuntu Jaunty 9.04. I then deleted the distribution's version and compiled ImageMagick 6.5.7 to reproduce the problem.

Thanks for any pointer as to where to look in the source code in order to debug this problem.

-Thomas

Re: Cropping bug with tif, png... ImageMagick 6.4.5 to 6.5.7

Posted: 2009-10-23T18:12:42-07:00
by fmw42
what does the verbose info say. might it have a virtual canvas that needs removing?

try

convert input -crop... +repage output

see http://www.imagemagick.org/Usage/crop/#crop_repage

Re: Cropping bug with tif, png... ImageMagick 6.4.5 to 6.5.7

Posted: 2009-10-24T01:10:55-07:00
by anthony
or the input file has a virtual canvas!

Code: Select all

   convert input +repage -crop ... +repage result
Remember JPEGs can not store virtual canvas information.

Re: Cropping bug with tif, png... ImageMagick 6.4.5 to 6.5.7

Posted: 2009-10-24T01:37:45-07:00
by tnetter
Thank you fmw42 and Anthony.
I confirm: the input file has a virtual canvas: it is a panorama generated by hugin. A repage was therefore necessary. I submitted an addendum to the -crop command line option documentation.

Here's the _Panorama Cropping using ImageMagick HOWTO_ in case Google leads someone here:
- Is a repage necessary? Find out whether the reference frame is translated:
identify myfile.tif
gives:
myfile.tif TIFF 978x338 978x338+3+119 8-bit DirectClass 1.261MiB 0.000u 0:00.000
Notice the +3+119 which indicates the reference frame is not at +0+0

- Repage the image:
convert +repage myfile.tif myfile-repaged.tif

- Crop the image:
convert -crop 950x330+10+10 +repage myfile-repaged.tif myfile-cropped.tif

Here's the addendum I submitted for the convert -crop command line option:
"It might be necessary to +repage the image prior to cropping the image to ensure the crop coordinate frame is relocated to the upper-left corner of the visible image. See -repage option. This is especially the case when cropping tiff files of stitched panoramas."