Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to crop a picture in the command line of Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report