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.
- $ Identify chart.png
- 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.
- $ 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: