PNG geometry and the *original* image canvas

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
gb96
Posts: 1
Joined: 2015-02-04T17:25:39-07:00
Authentication code: 6789

PNG geometry and the *original* image canvas

Post by gb96 »

Used the following to crop a directory full of PNG images:

Code: Select all

mogrify -crop 1080x300+0+0 *.png
Expected resulting images to be 1080x300 however I did not realize that the PNG preserves geometry reference of the *original* image, and the source images to the above command were the output of a previous been crop, as follows:

Code: Select all

mogrify -crop 1080x1920+0+181 *.png
The end result of the 1080x300+0+0 crop have dimensions of only 1080x119 and ruined all the images. So glad I have a backup of the source images somewhere!

I think this default behavior is counter-intuitive, and should be either changed or at least better documented. The initial crop and subsequent operations could have been performed by different users or processes and so geometry should by default be relative the the input image, not to some ancient "original" version.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG geometry and the *original* image canvas

Post by fmw42 »

You probably want to add +repage after the crop, if you do not want to save the virtual canvas. If they were cropped previously with the virtual canvas, put another +repage before the crop.
Post Reply