Editing images on a Linux command line using ImageMagick

Every time we deal with images on the command line, we need to install or use any of the command line tools. Few of them include GraphicsMagick, Scrot, Feh, Exiv2, etc. These tools allow us to convert, and also help us resize, compare, animate and view images. Each tool has its own use. In this tutorial, we will learn how to perform basic image editing from the Linux command line if necessary. For this purpose we will use ImageMagick, which is used most often.

Resize Linux command line image

To resize an image in a Linux terminal, you need to follow these steps.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Search Terminal Application

Step 2: Now click on Terminal and wait for the terminal to open.

Open the Terminal app

Editing images on a Linux command line using ImageMagick

Step 3: After opening the terminal you will have the following screen:

The terminal is open

Step 4:

Then, once the terminal has been opened, we need to install ImageMagick to continue resizing, the command used for this purpose: “Sudo apt-get install ImageMagick.”

Install imagemagick

Enter the required credentials to continue.

enter password

Installation will begin and your screen will appear as shown below.

Install app

To continue the installation, enter Y.

After the final installation, this is displayed on the command line. ImageMagick Installation Successful

Now we want to resize the image. It is currently on the desktop with the name index.png

Desktop Image Location

Editing images on a Linux command line using ImageMagick

We will move our current directory to the desktop where our image is located.

go to the desktop folder

The image that we want to change is index.png, so we write a command with the original image name, and then adjust the percentage to which we want to resize, and then save it in a new file name. with the extension .png.

Resize Image

This creates a new image with a 60% resize newindex.png

Image has been resized

Editing images on a Linux command line using ImageMagick Editing images on a Linux command line using ImageMagick

Original Image Size

Two images show different sizes of the same index.png, the size of which we changed with the command.

Smaller image

Convert file type

Since the above image file was in png format, and we want to convert it to .jpg Now we will enter a command for this, using the convert command and writing the file type next to the type to which we want to convert.

Convert file from png to jpg

Converted file in the list

Editing images on a Linux command line using ImageMagick

So, the file is now converted to another type of .jpg

Convert PNG to JPEG file successfully

Get information about a specific image

If you want to get any image information, just enter the command.

identify –ping imageName.jpg

get image information using the identification command

All information about the image is disclosed.

information is displayed

For more details, we simply type this command.

use verbose output

The result we get.

detailed result of team identification

Flipping image

If we plan to flip the image on the Linux command line, it’s not difficult, just write the hidden –flip imageName.jpg FlippedImageName.png. This will allow us to achieve the desired result.

Command flip image

A new image called Flipped-index on the desktop can be seen.

File in list

Editing images on a Linux command line using ImageMagick

This is an inverted image as soon as we opened it. As you can see, this is the image we wanted to get. Our image was rotated 90 degrees, as shown in the following figure.

Inverted image

Here’s how we can flip our images using the command line.

Color list

To find out all the colors used in the image, we use a simple command to help us find out the colors used to create the image.

Get color list

The output will display a list of the colors that we have for our index image.

Color list

So, here is how we get the color list of any particular image that we want.

Convert a color image to black and white

We can also convert a color image to black and white using the Linux command line. Command

Convert image to black and white

We can also add a frame to any desired image, and it can be of any color, as in our example we added a red frame. The command used to do this

Add border to image

The index border is the border of the added image.

Image list

Editing images on a Linux command line using ImageMagick

An open image has a red border, the following illustration shows the same thing.

Picture with frame

Negative image

We can also cancel any image whenever we want using the following command:

deny image

A negative index is created on the desktop.

list of files

Editing images on a Linux command line using ImageMagick

The negated image is as follows:

Negative color file

Convert image to PDF

Any image can be converted to PDF using the command.

Convert image to pdf on shell

Where we just write convert imageName *. * FileName.pdf.

A new PDF file will be created for this particular image, displayed on the desktop of our system.

list of files

Editing images on a Linux command line using ImageMagick

Thus, the image was saved in a PDF version, as shown below:

Pdf file


Finally, we will see the command, if you want to edit the image yourself using the ImageMagick GUI, run the following command.

Show image

So, a graphical interface will eventually appear, allowing you to make changes.

Imagemagick display


In this tutorial, we discussed many interesting ways to edit an image. The most common method used for editing is ImageMagick, so in this tutorial we also used it and installed it first. Then we saw many applications and actions that we can perform using ImageMagick. First, we did resizing the image, then we learned how to change the file type to suit our needs, then we saw how to display image information, then we saw how we invert the image, then we saw ways to see the colors in the image. Then we saw the technique of converting an image painted in black and white, and added a frame (color) to the image. Later we converted the image to a PDF file. Finally, we saw how we can display the GUI so that we can use ImageMagick. These are the basic but necessary commands that a Linux user can learn to edit an image on Linux.

Editing images on a Linux command line using ImageMagick