Linux Mint

How to Crop an Image from the Command Line on Linux Mint 21

Cropping an image is a basic image editing operation, and it can be done using various tools and software, including those available on the Linux Mint operating system. ImageMagick is one of the best and most versatile command line-based tools for manipulating and enhancing digital images.

This tool can be used for converting the format of the file, adding effects, cropping, and resizing the image. If you are looking for the installation process, and steps to use ImageMagick on Linux Mint 21 read this guide.

How to Crop an Image from the Command Line on Linux Mint 21

If you want to crop the image to remove the blank space then install ImageMagick. It contains a set of command line tools to convert images. First, install the ImageMagick through the apt command:

$ sudo apt-get install imagemagick

After installing this command line tool, identify the size of the image you want to crop using the identify command, it will give the dimensions of the respective image and for it below is the syntax:

$ identify <image-name>

For example:

$ identify images.jpeg

For displaying the selected image, you can use the display command with the name of the image and format:

$ display images.jpeg

Next, determine the following two aspects of the image:

  • The position at which the image crop will start
  • The size of cropped rectangle

After determining, use convert with crop option for trimming the image and converting it into a desired size, below is the syntax for the crop command one can follow:

$ convert <image-name> -crop <desired-image-dimension> <New-image-name>

Here, I am cropping the image from the top left more specifically x=10 and y=5 and I have set the size of the image as 250*120:

$ convert images.jpeg -crop 250x120+10+5 images-cropped.png

The separate file with the cropped edition in the name will be saved in the directory. Use the identify command to verify the size of the cropped image:

$ identify images-cropped.jpeg

You can also use the display command to display your cropped image:

$ display images-cropped.jpeg

How to Remove ImageMagick from Linux Mint 21

If you no longer need this tool, follow the below command to completely uninstall it from your Linux system:

$ sudo apt-get remove --autoremove imagemagick

Bottom Line

The ImageMagick is a versatile command line tool that can be used for cropping images in a variety of ways by specifying the custom crop region. This tool is efficient and comes with many options to edit images through command line on Linux. It can convert 200 types of image formats using the command line. It also supports animation, color management, and Rendering. Install this tool from the default repository and to crop any image on Linux Mint 21.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.