DobotJr
DobotJr

Reputation: 4049

Cropping an image using Jcrop and Imagemagick

I'm confused on how the -crop function works in Imagemagick.

I have the following values from Jcrop.

(x1,y1), (x2,y2), width and height.

And following command:

exec("convert $target_path -crop ".$w."x".$h."+$x+$y +repage $target_path");

Original image:

enter image description here

Result after crop:

enter image description here

My question is, How do I used the coordinates and dimensions from Jcrop, and use them with Imagemagick?

Upvotes: 0

Views: 760

Answers (2)

DobotJr
DobotJr

Reputation: 4049

I feel like an idiot.

I had style='max-width:500px;' on my image during the crop. Removed the style and now it's working.

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 207465

I have no idea what values you are passing into convert, but your command needs to look something like this to extract the light region -if that is your aim:

convert x.png -crop 240x240+120+100 out.png

enter image description here

The first 240 is the width of the cropped area, and the second 240 is its height. The 120 is the x-offset across from the top-left corner and the +100 is the y-offset down from the top.

Or, in general terms, you specify the crop like this

convert input.png -crop ${x}x${y}+${a}+${b} output.png

enter image description here

Upvotes: 1

Related Questions