InfoHeap
Tech tutorials, tips, tools and more
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. How to compress screenshot images using imagemagick convert
  2. Imagemagick – how to create animation on command line
  3. How to resize image (including animated gif) using Image magick convert
  4. Get image width and ppi using imagemagick identify on command line
  5. Find image unique colors and bit depth using imagemagick identify
  6. How to edit animated gif speed (FPS) using imagemagick convert
  7. How to install Imagemagick on Ubuntu Linux
  8. Bulk convert jpeg files to png using sips on mac
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

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | 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

Copyright © 2023 InfoHeap.

Powered by WordPress