As we all know, Linux is an OS like Windows and Macintosh. In Linux, we can adopt different methods to Resize, Convert & Modify images. But there is a specific way of doing it using Linux terminal. For this purpose we use a program called ImageMagick. Using ImageMagick we can easily operate an image using Linux terminal. ImageMagick can be used to perform different operations.
Following topic will introduce you to ImageMagick’s basics and show you how to do different procedures on images.
In the Linux OS, ImageMagick isn’t the built-in program. We have to follow few steps for installations of imagemagick on Linux. Ubuntu is a Linux based OS. To install Imagemagick on Ubuntu, we use following command:
sudo apt-get install imagemagick
Once it is installed, we can do a lot of awesome things. Some of which are as follows:
- Converting Between Formats
We can change formats of an image using imagemagick .To convert an image we have to use some commands just like we did before in the installation process. It simply takes one image performs operation on it and saves it with the same file name but with different format. We use following command to convert a PNG file named Image.png in the directory and creates a JPEG image from it:
convert Image.png Image.jpg
- Resizing Images
We can do different things using convert command. For example we can also quickly resize an image using convert command. Following command makes ImageMagick to resize an image of 1080 pixels in width and 720 pixels in height.
convert example.png -resize 1080×720 example.png
ImageMagick will not alter the aspect ratio if you use above command. If you want to force the image to be an exact size even if it alters the aspect ratio we simply introduce an exclamation (!) point.
convert example.png -resize 1080×720! example.png
We can also change width or height separately. ImageMagick will resize the image to specific width or height. To change an image width following command will be used:
convert example.png -resize 200 example.png
Similarly for changing height we use following command:
convert example.png -resize x100 example.png
- Rotating an Image
We can also rotate an image using ImageMagick. For rotating an image named Image1 to angle of 90 degrees we use following command:
convert Image1.jpg -rotate 90 Image1-rotated.jpg
Note: Same rule applies for overwriting a file
- Applying Effects
It is always fun to add some nice effects to an image to make it look decent. ImageMagick can do the exact thing for you. For applying an effect following command is used. This will apply ‘charcoal’ effect on image named “Image2”:
convert Image2.jpg -charcoal 2 Image2-charcoal.jpg
There are many effects like charcoal we used earlier one of which is ‘Implode’ effect.
It will add a goofy look to your image as there is a black hole at the center of the image. Following command is used to apply the “Implode” effect:
convert Image3.jpg -implode 1 Image3-imploded.jpg
- Combining Operations
All the operations we have used earlier can be combined and performed with a single command .we can resize, rotate, apply an effect, and convert an image to another format:
convert Image.png -resize 400×400 -rotate 180 -charcoal 4 -quality 95 Image.jpg.
We are just scratching the surface here we can do incredible lots of things using ImageMagick.
So, these are some of the techniques used to resize the images in Linux. You just need to follow the instructions wisely to get the work done.