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.
Step 2: Now click on Terminal and wait for the terminal to open.
Step 3: After opening the terminal you will have the following screen:
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.”
Enter the required credentials to continue.
Installation will begin and your screen will appear as shown below.
To continue the installation, enter Y.
After the final installation, this is displayed on the command line.
Now we want to resize the image. It is currently on the desktop with the name index.png
We will move our current directory to the desktop where our image is located.
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.
This creates a new image with a 60% resize newindex.png
Two images show different sizes of the same index.png, the size of which we changed with the command.
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.
So, the file is now converted to another type of .jpg
Get information about a specific image
If you want to get any image information, just enter the command.
identify –ping imageName.jpg
All information about the image is disclosed.
For more details, we simply type this command.
The result we get.
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.
A new image called Flipped-index on the desktop can be seen.
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.
Here’s how we can flip our images using the command line.
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.
The output will display a list of the colors that we have for our index image.
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
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
The index border is the border of the added image.
An open image has a red border, the following illustration shows the same thing.
We can also cancel any image whenever we want using the following command:
A negative index is created on the desktop.
The negated image is as follows:
Convert image to PDF
Any image can be converted to PDF using the command.
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.
Thus, the image was saved in a PDF version, as shown below:
Finally, we will see the command, if you want to edit the image yourself using the ImageMagick GUI, run the following command.
So, a graphical interface will eventually appear, allowing you to make changes.
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