STRANGE ISSUE WITH CROP COORDINATES

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
goyop
Posts: 12
Joined: 2009-08-11T15:11:50-07:00
Authentication code: 8675309

STRANGE ISSUE WITH CROP COORDINATES

Post by goyop »

I have been using the crop function to extract sections for MJPEG video clips. It has worked very well for a couple of years and occasionally we change the crop box due to different needs. Up to now it is very simple. I just take one of the JPGs, bring it into PS and lay a pixel grid on top. Then starting in the upper left corner at 0,0 I call out the Y starting point and Y dimension, followed by the X.

Over the last couple days in trying to make some simple crop changes I am running into a strange problem with the new coordinates causing unexpected and hard to figure results. I tried these changes on two machines with different versions of IM.

A head scratcher for me. I am fully prepared to be embarrassed by a simple explanation but I am not seeing it.

Thanks,

Greg

*** FIGURED IT OUT ALTHOUGH STILL UNCERTAIN ABOUT NEGATIVE COORDINATES BUT WE ARE NOT USING THEM. I DO FULLY UNDERSTAND X Y AND Z AXIS *****
Last edited by goyop on 2011-02-26T19:20:13-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: STRANGE ISSUE WITH CROP COORDINATES

Post by fmw42 »

crop_0x300+0+300.jpg. It produced a 300 pixel horizontal band across the entire source image and not starting at 0,0
0x300+0+300 is NOT a 300x300 region --- this is 0 width and 300 y offset from the top left

you cannot use a size of 0 for Width
goyop
Posts: 12
Joined: 2009-08-11T15:11:50-07:00
Authentication code: 8675309

Re: STRANGE ISSUE WITH CROP COORDINATES

Post by goyop »

Thanks for the tip. Your comment allowed me to think through the situation and come up with a fix.

FYI, IM does allow you to enter 0x300 and get an output. That is part of the confusion. It gave me a 300 pixel high band that was 1600 pixels wide using the command that you quoted. Try it if you like but I was putting in all sorts of erroneous values and getting output. Not the output I wanted but output.

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

Re: STRANGE ISSUE WITH CROP COORDINATES

Post by anthony »

fmw42 wrote:
crop_0x300+0+300.jpg. It produced a 300 pixel horizontal band across the entire source image and not starting at 0,0
0x300+0+300 is NOT a 300x300 region --- this is 0 width and 300 y offset from the top left

you cannot use a size of 0 for Width.
Actually you CAN use a zero width. A zero is nonsensical and so IM replaces it with the virtual canvas width.

So what you get is a strip or row crop across the whole (X wise) length of the image from 0 virtual canvas to the current virtual canvas width. If the image is smaller than or more typically te same size as the virtual canvas (+repage) you will get everything in that strip.

If the image is larger than, or not completely located on its virtual canvas (also a nonsensical situation but could be done usefully on purpose) you are limited to what part of the image is on the virtual canvas according to its actual size and offset.

This is all explained in IM Examples, Crop, Strip Cropping
http://www.imagemagick.org/Usage/crop/#crop_strip
And is also used in the next sections of Quadrant Cropping, and cropping with Negative Offsets.
The virtual canvas is also used to effect 'tile cropping' too.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: STRANGE ISSUE WITH CROP COORDINATES

Post by fmw42 »

Well I stand corrected on the fact that 0 width or height can be used, but it seems non-sense to me with no apparent purpose.
Post Reply