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

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
tnetter

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tnetter

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

Post 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."
Post Reply