Cropping relative to gravity

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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Cropping relative to gravity

Post by whugemann »

I have just tried to crop an image relative to its centre via:

Code: Select all

convert input.tif -gravity center -crop 500x1000 output.tif
but IM just ignored the gravity setting. Taking a look at http://www.imagemagick.org/Usage/crop/#crop_gravity, I found out that you obviously have to add "+0+0". Is there any reason for that? IMHO, one expects a zero offset to be the default value and wonders why the code is not functioning. It's not a real bug, but a source of unneeded confusion.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping relative to gravity

Post by fmw42 »

Wolfgang,

I believe leaving off the +0+0 is a flag so that you get tiled cropping with multiple output images or layers. Is that what you wanted? see http://www.imagemagick.org/Usage/crop/#crop_tile

If just a single crop relative to the center then you do need to add +0+0 to avoid the tile cropping.

Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping relative to gravity

Post by anthony »

Correct. And Tile cropping ignores gravity! It only does cropping from the top left virtual canvas corner.

If you want something else (like equal remainders around the edge) then you may need to do some extra calculation (at least at this time). For example...
http://www.imagemagick.org/Usage/crop/# ... e_centered

I suppose we could make the tile cropping gravity dependant to determine how remainders are arranged. I'll add it to my ToDo, but IMv7 Shell API re-write is taking priority at this time.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Cropping relative to gravity

Post by whugemann »

OK, now I understand: You have to add "+0+0" in order to prevent tiling. If you however write

Code: Select all

convert input.tif -gravity center -crop 500x1000 output.tif
you will get only the single upper left tile as a result, without any warning message (even if you add -regard-warnings). In order to initiate tiling you have to write

Code: Select all

convert input.tif -gravity center -crop 500x1000 output_%02d.tif
And with crop-tiling ingnoring the gravity setting, things become even more confusing for those who are not entirely familiar with the settings of the crop operator.
Wolfgang Hugemann
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping relative to gravity

Post by anthony »

I thought TIF was multi-image file format, though I know for a fact than many programs (like the default windows imge display program - whatever that is) does not understand multi-image tiff.

As such you will probably find the first image actually did contain all the tiles, not just the firts top-left corner.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply