There are many options for editing images in Ubuntu, but personally most of them I don’t like. If I want to resize an image, I don’t feel like having to wait the time it takes GIMP to open it. We can always install nautilus-image-converter to rotate and rotate right-click images from Nautilus but why install a package, which above does not display the text well, if we have a default one installed that does? In this article we will show you how to edit, convert, resize and a few more things the pictures from the Ubuntu Terminal.
Best of all, what we are going to explain in this guide can be applied to several images at once. For example, if we want to rename 10 photos without having to right-click, choose “Rename” and put the name 10 times, we can do it using ImageMagick, The default image viewer for Ubuntu and other distributions, including Ubuntu MAT, my favorite. Below are several example commands for performing several of these operations using the Ubuntu Bash.
ImageMagick comes installed in many distributions, such as the aforementioned Ubuntu or Ubuntu MAT. If your distro does not have it installed by default, you can install it by opening a terminal and typing the following command:
sudo apt-get install imagemagick
If, for example, you do a tutorial of many captures, these will have a name that will have nothing to do with what we want to show. Thanks to ImageMagick we can name from the terminal with a very simple command. As you will see later, we can change the format of the images and use exactly the same order, but appropriate to our task. It would be as follows:
convert *.png prueba.png
By holding the extension and adding an exit word, all it will do is save them all with the same name, but with a different number.
Almost all editions of this guide use the key convert. To resize images with ImageMagick from the Terminal we will write the following command, where “test” will be the name of the image we want to convert to another format:
convert prueba.png -resize 200×100 prueba.png
With the previous order we will have resized an image at a size of 200 × 100 pixels. The first value is the width size and the second height. If we use the same name, the resulting image will replace the original. If we only want to change the width and the height is proportional, we will write the following command, where 200 would be the size chosen in pixels:
convert prueba.png -resize 200 prueba.png
If we want it to be 200 pixels high, we should stop empty the first value (“Empty” x100), so we would write the following command:
convert prueba.png -resize x100 prueba.png
Sometimes the exact valuesBut if we want it to be so, we can write the following command, where 200 × 100 would be the size chosen:
convert prueba.png -resize 200×100! prueba.png
If what we want is rotate images, We can do it with the following order, where 90 would be the degrees of inclination:
convert prueba.jpg -rotate 90 prueba-rotado.jpg
It will add the text we set to the output file, as long as we write it differently.
Edit the format of the images
ImageMagick also allows us convert images to another format directly from the terminal. We would do it with the following order:
convert prueba.png prueba.jpg
If what we want is just lower the quality to send the images by mail, for example, we would write the following order, where the number is the percentage of quality:
convert prueba.png -quality 95 prueba.jpg
If we want to perform different modifications of this type to an image, we can do it by combining operations. Below is an example to resize, rotate 180º and lower the quality of an image to 95%.
convert prueba.png -resize 400×400 -rotate 180 -quality 95 prueba.jpg
But what I like most is this, edit many images at once. Before editing multiple images, it’s worth putting them all in the same folder. I usually leave them on the desktop, so I write the command first:
Once inside the folder, we type the following command to resize all the .png format images in the Desktop folder to 830 pixels wide and add it to the word “first”:
for file in *.png; do convert $file -resize 830 primera-$file; done
Basically, what we tell you is “all files that are inside this folder and have .png format; do the conversion from resize to 830 wide and add it first- to the file name; the end«. If you edit a lot of images, it might be worth it. What do you think?