Problem in Cropping the image

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
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Problem in Cropping the image

Post by helloworld »

I am trying to convert an image to the below dimensions with below command and the cropped image i get is not the expected image.

Command

convert plant.jpg 2325x3750+2358+3820 plant1.jpg

W: 2325
H: 3750
X: 2358
Y: 3820

Error

Its not giving me what i expected.

Original Image:
http://f.cl.ly/items/1s0z3j3z3c2o3a23031G/plant.jpg

Cropped Image:
http://f.cl.ly/items/21073D1l3d1128253s0N/plant1.jpg

So basically i cropped only the plant
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem in Cropping the image

Post by snibgo »

You are missing the keyword "-crop".
snibgo's IM pages: im.snibgo.com
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Re: Problem in Cropping the image

Post by helloworld »

Sorry i forgot to add -crop in the image. But i typing the correct command.

convert plant.jpg -crop 2325x3750+2358+3820 +repage plant1.jpg

still getting the same image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem in Cropping the image

Post by fmw42 »

helloworld wrote:Sorry i forgot to add -crop in the image. But i typing the correct command.

convert plant.jpg -crop 2325x3750+2358+3820 +repage plant1.jpg

still getting the same image.

What version of IM and platform? Can you provide a link to your input and output images?

The problem is you are supplying an offset outside the image. The +X+Y are not the bottom right corner coordinatess but the offset for the top left. The WxH is the desired size of the cropped region starting at +X+Y.
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Re: Problem in Cropping the image

Post by helloworld »

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem in Cropping the image

Post by snibgo »

As Fred says.

1. What width should the output be?

2. What height should the output be?

3. What x-coordinate in the original should the output start at?

4. What y-coordinate in the original should the output start at?
snibgo's IM pages: im.snibgo.com
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Re: Problem in Cropping the image

Post by helloworld »

W: 2325
H: 3750
X: 2358
Y: 3820
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem in Cropping the image

Post by snibgo »

But your original is only 3000 pixels wide. If the output starts at x-coord 2358, and is 2325 pixels wide, 2358+2325 = 4683. 4683 > 3000.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem in Cropping the image

Post by fmw42 »

snibgo wrote:But your original is only 3000 pixels wide. If the output starts at x-coord 2358, and is 2325 pixels wide, 2358+2325 = 4683. 4683 > 3000.
Yes. I pointed that out above. I think the OP does not understand IM syntax for cropping.

"The problem is you are supplying an offset outside the image. The +X+Y are not the bottom right corner coordinates but the offset for the top left. So, WxH is the desired size (dimensions in pixels) of the cropped region starting at pixel +X+Y relative to the top left corner of the input image."


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

W: 2325
H: 3750
X: 2358
Y: 3820
How did you determine these coordinates? What tool did you use to measure them? Was that measured in pixels?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem in Cropping the image

Post by snibgo »

Perhaps this will help the OP:

Code: Select all

+------------------------------------+
|           ^                        |
|           |                        |
|           Y                        |
|           |                        |
|           V                        |
|       +------------+ ^             |
|<--X-->|            | |             |
|       |            | |             |
|       |            | H             |
|       |            | |             |
|       |            | |             |
|       |            | |             |
|       +------------+ V             |
|                                    |
|       <-----W------>               |
|                                    |
+------------------------------------+
snibgo's IM pages: im.snibgo.com
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Re: Problem in Cropping the image

Post by helloworld »

I used photoshop to get those dimensions.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem in Cropping the image

Post by fmw42 »

helloworld wrote:I used photoshop to get those dimensions.

Were they in pixels or some other units? Were you getting the coordinates from the cursor or from the rulers. Were they the top left and bottom right corners? Or were they the width, height and top left x,y coordinates.

Something is obviously wrong if you are measuring pixels that are outside the bounds of your image.

What features are you trying to crop? Can you draw a box in PS on your image to show the area you want? I can open that in PS and see what the correct coordinates should be for IM.

If you open the image in PS and open the Info window, then select the crop tool and draw a box, the Info panel should show you the Width and Height and top left X,Y coordinates in pixels. Before you do that open the Preferences panel and select Units and Rulers and set the Units to pixels
helloworld
Posts: 69
Joined: 2013-05-22T09:42:33-07:00
Authentication code: 6789

Re: Problem in Cropping the image

Post by helloworld »

Got the solution for this. Its fixed thanks a lot.
Post Reply