InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

ImageMagick tutorials

  • Install Imagemagick on Mac
  • Install Imagemagick on Ubuntu
  • Create animated gif using Mac preview
  • Create animated gif on command line
  • Edit animated gif speed
  • Find image width and ppi
  • Find image unique colors and bit depth
  • Resize image dimention
  • Compress images
  • Crop image
 
  • Home
  • > Tutorials
  • > Linux/Unix Command Line
  • > ImageMagick

How to crop an image using imagemagick convert

By admin on Dec 6, 2015

Imagemagick convert is pretty handy tool to manipulate images and can be used to crop an image. This can be useful in automation and also doing bulk operation on images. We’ll be using the following image (convert-crop-img1.jpg width,height=480×320) for the purpose of this tutorial.
convert-crop-img1

This tutorial is performed on Mac (OS X Yosemite) with Imagemagick version 6.9.2-7.

Crop image using target width,height and offset in pixel

Crop the image to target size 240×160 with crop starting point at x=100,y=50

$ convert -crop 240x160+100+50 convert-crop-img1.jpg convert-crop-img2.jpg

Here is the outcome image (convert-crop-img2.jpg):
convert-crop-img2

Crop image using target width,height in percentage

Crop the image to target size 50%x50% with crop starting point at x=100,y=50

$ convert -crop 50%x50%+100+50 convert-crop-img1.jpg convert-crop-img3.jpg

Here is the outcome image (convert-crop-img3.jpg):
convert-crop-img3

Crop image using both target width,height and offset in percentage

Crop the image to target size 50%x50% with crop starting point at x=25%,y=25%

$ OFFSETX=$(identify -format '%[fx:w/4]' convert-crop-img1.jpg)
$ OFFSETY=$(identify -format '%[fx:h/4]' convert-crop-img1.jpg)
$ echo $OFFSETX $OFFSETY
120 80
$ convert -crop 50%x50%+$OFFSETX+$OFFSETY convert-crop-img1.jpg convert-crop-img4.jpg

Here is the outcome image (convert-crop-img4.jpg):
convert-crop-img4

Suggested posts:

  1. Get image width and ppi using imagemagick identify on command line
  2. How to edit animated gif speed (FPS) using imagemagick convert
  3. Mac brew – how to relink installed binaries for a package
  4. WordPress mysql query to get all custom keys and values for a post
  5. How to install node.js on Ubuntu Linux
  6. How to create animated gif using Mac preview
  7. How to compress screenshot images using imagemagick convert
  8. Php look ahead and look behind regex examples
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged ImageMagick, Linux, Linux/Unix Command Line, Mac, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress