Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to crop a picture in the command line of Linux

Shulou Source: shulou.com Published: 2022-06-01 15:51:41 10月04日 Update

This article introduces the knowledge of "how to crop pictures in the command line of Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

When it comes to converting or editing image files in Linux, ImageMagick is undoubtedly one of the most well-known all-in-one software. It contains a complete set of command-line tools to display, convert, or copy more than 200 types of raster or vector image files, all on 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, clipping).

If you want to clip the image to remove white space, you can use the two command-line tools that come with ImageMagick. If you have not already installed ImageMagick, please refer to this guide to install it.

In this tutorial, let's clip the following PNG image. We want to remove the edges on the right and bottom 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.

The code is as follows:

$identify chart.png

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 two things to do for image clipping: (1) the location of the beginning of the clipped image (2) the size of the clipped rectangular area.

In this example, let's assume that the image clipping starts at the upper left corner, more precisely in x=20px and y=10px, in which case the clipped image size is 1200x700px.

The tool for clipping images is convert. After using the "- crop" option, the convert command clips a rectangular area in the input image.

The code is as follows:

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

Specifying the input image as chart.png,convert saves the clipped image as chart-cropped.png.

This is the end of the content of "how to crop pictures in the command line of Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Images commands files tools input pictures realism next code content region size size more knowledge rectangle special precision learning in that case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Shulou Technology MySQL Shulou Tech Info