[Resolved] Negative Offsets in geometry when cropping

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
weakish

[Resolved] Negative Offsets in geometry when cropping

Post by weakish »

I have some difficulties in understanding the usage of negative offsets in geometry.

Code: Select all

convert -crop 50%x100%+0+0 in.jpg out.jpg
convert -crop 50%x100%-0-0 in.jpg out.jpg
give the same result. (Got the left half of the picture.)

Can anyone give some hints? Thanks in advance.
Last edited by weakish on 2008-11-18T06:04:15-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Negative Offsets in geometry when cropping

Post by fmw42 »

weakish wrote:I have some difficulties in understanding the usage of negative offsets in geometry.

Code: Select all

convert -crop 50%x100%+0+0 in.jpg out.jpg
convert -crop 50%x100%-0-0 in.jpg out.jpg
give the same result. (Got the left half of the picture.)

Can anyone give some hints? Thanks in advance.

+0+0 and -0-0 both refer to the upper left corner pixel. so you won't see any differences. If you put +20+20, you will have an image that has its upper left corner starting 20 pixels in from your original. Negative offsets will likely crop 20 pixels from the lower right corner and may disregard your size specification, I am not sure. If you want to crop from one side or corner add -geometry and use positive offsets.

see http://www.imagemagick.org/script/comma ... s.php#crop

Also your syntax should possibly be

convert in.jpg -crop ... out.jpg

See http://www.imagemagick.org/Usage/basics/#cmdline Although in this case in likely does not matter as your will be cropping as you read the input in your syntax rather than loading the image and then cropping it in the latter syntax (assuming you can use -crop while reading the input).

Also note that after cropping, you want to remove the virtual page information using +repage

convert in.jpg -crop ... +repage out.jpg

see http://www.imagemagick.org/Usage/crop/#crop
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Negative Offsets in geometry when cropping

Post by anthony »

The offset only specifys the position of the rectangle you give

so 100x100-20-20 will specify a rectangle that is 20 pixel to the left and above the top of the image. Rather useless unless your image is a layer image with a negative offset (most images are not).

If you do not specify the size of the crop rectangle it is the size of the virtual canvas, which in most image is actual image size (but not always).

If you don't specify a offset, you get a tiled crop.

Each of these types are exampled in IM examples, Cutting and Borders.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
weakish

Re: Negative Offsets in geometry when cropping

Post by weakish »

Thanks to your replies. Now I have a better understanding on this expression of geometry in IM.

I had confused it with the geometry concept in X window, where -0-0 refers to the right down corner.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [Resolved] Negative Offsets in geometry when cropping

Post by anthony »

I figured. :)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply