How to trim an image on the Linux command line

Source: Internet
Author: User
Tags imagemagick

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 to display, convert, or copy raster or vector image files of more than 200 types, all at the command line. ImageMagick can be used for a variety of image editing tasks, such as converting file formats, adding special effects, adding text, and changing images (resizing, rotating, flipping, cropping).

If you want to trim the image to remove whitespace, you can use the two command-line tools that ImageMagick comes with. If you have not installed ImageMagick, please refer to this guide to install it.

In this tutorial, let's trim the following PNG image. We want to remove the right and bottom edges of the image so that the icon is centered.

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

    1. $ identify chart. PNG
    1. Chart. PNG png 1500x1000 1500x1000+0+0 8-bit directclass 31.7KB 0.000u 0:00.000

As shown above, the input image is 1500x1000px.

Next, determine the two things you want to do with the image clipping: (1) The position at which the cropped image begins (2) the size of the clipped rectangular area.

In this example, let's assume that the image clipping starts at the upper-left corner and that the more precise point is in x=20px and y=10px, so the cropped image size is 1200x700px.

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

    1. $ convert Chart. PNG -crop 1200x700++ Chart-cropped. PNG

Specifying the input image as the Chart.png,convert command stores the cropped image as Chart-cropped.png.

How to trim an image on the Linux command line

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.