ImageMagick Tutorial: How to crop images in Linux Command lines

Source: Internet
Author: User
Tags crop image imagemagick

ImageMagick Tutorial: How to crop images in Linux Command lines

Q: I want to remove white spaces in image files. Is there any convenient way to crop image files in the Linux Command Line?

When it comes to converting or editing image files in Linux, ImageMagick is undoubtedly one of the most well-known integrated software. It contains a complete set of command line tools for displaying, converting, or copying grating or vector image files of more than 200 types, all done under the command line. ImageMagick can be used to edit diverse images, such as converting file formats, adding special effects, adding text, and changing images (resize, rotate, flip, and crop ).

If you want to crop the image to remove the blank space, you can use the two command line tools that come with ImageMagick. If you have not installed ImageMagick, refer to the following useful links for installation.

Use ImageMagick to draw a three-color schematic diagram

In Linux, PHP supports ImageMagick and MagicWandForPHP.

Image Magic with ImageMagick in Linux

Installation of ImageMagick and MagicWand For PHP in Linux

Install ImageMagick and JMagick in Linux

In this tutorial, let's crop the following PNG images. We want to remove the right and bottom edges of the image to center the icon.

First, identify the size (width and height) of the image file ). You can use the identity command.

  1. $ Identify chart.png
  1. Chart.png PNG 1500x10001500x1000 + 0 + 08-bit DirectClass31.7KB0.000u0: 00.000

As shown above, the input image is 1500x1000px.

Next, determine the two things to do in image cropping: (1) position at the beginning of image cropping (2) Size of the rectangular area.

In this example, let's assume that the image clipping starts from the upper left corner, and the more precise points are in x = 20px and y = 10px. In this case, the size of the cropped image is PX.

The tool used to crop images is convert. With the "-crop" option, the convert command will crop a rectangular area in the input image.

  1. $ Convert chart.png-crop 1200x700 + 20 + 10 chart-cropped.png

The input image is chart.png, And the convertcommand will store the saved image as chart-cropped.png.

For details about ImageMagick, click here
ImageMagick: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.