Page 1 of 1

Cropping relative to gravity

Posted: 2012-03-05T02:05:33-07:00
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.

Re: Cropping relative to gravity

Posted: 2012-03-05T11:45:44-07:00
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

Re: Cropping relative to gravity

Posted: 2012-03-06T04:15:42-07:00
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.

Re: Cropping relative to gravity

Posted: 2012-03-13T00:55:11-07:00
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.

Re: Cropping relative to gravity

Posted: 2012-03-14T22:01:16-07:00
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.