Monday, October 26, 2015

Extract a subset of an image using ImageMagick

ImageMagick's convert tool (now called magick in version 7) can be used to perform a large number of tasks. Recently, I had to extract out a portion of a large number of images at certain locations and at certain dimensions. Performing this interactively is tedious especially if there are hundreds of photos. Luckily, magick can be used to do the job in batch, with the right parameters.

The input image for extracting a subset

  1. Open up a Command Prompt.
  2. At the prompt, type in the following:

    C:\> magick input.jpg -crop 328x380+6776+192 output.jpg

    Note: 328 is the image width to extract
    380 is the input image height to extract
    6776 is the input image top left pixel x location to extract
    192 is the input image top left pixel y location to extract

  3. Press RETURN.

    The image is extracted out.

No comments:

Related Posts with Thumbnails