How to crop image using ImageMagick

To crop an image using ImageMagick, you need to specify the X and Y coordinates of the top corner of the crop rectangle and the width and height of the crop rectangle. Use the mogrify command if you want the images to be replaced in-place or use the convert command otherwise to make a copy.

If you want the crop rectangle to start at top corner X: 50 Y: 100 and the crop rectangle to be of size W: 640 H:480, then use the command:

$ mogrify -crop 640x480+50+100 foo.png

To write the cropped image to a new file:

$ convert foo.png -crop 640x480+50+100 out.png

Tried with: ImageMagick and Ubuntu 14.04


6 thoughts on “How to crop image using ImageMagick

  1. This works very well. however using the convert method creates multiple images. One which is actually required and the rest is junk. I guess there is another flag to be set to create just one output.


    1. You can get rid of the junk file by suffixing your “convert” or “mogrify” command with “+0+0,” as in “mogrify -crop 800×1200+0+0 pict.jpg.” It crops from top left and cuts (and disposes of) the image, leaving no “chopped-off” junk files. (Redundant, ‘ent I?)

      Liked by 1 person

  2. Many thanks to you. I couldn’t use β€œconvert” (β€œchopped-off” always remain), but β€œmogrify” works perfectly.


  3. Hey, Can you please tell me that how i can implement this in Nodejs
    $ convert foo.png -crop 640×480+50+100 out.png


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.