Installing ImageMagick
Before we start, we need to first install ImageMagick on our system. On Ubuntu or any Debian-based distro: On Fedora: On Arch Linux
View the Image Information
With ImageMagick installed, you can now use it to view all the information about an image.: For example, to check the original dimension of the image, use the following command: For a photo, you can also view the Exif data:
Resizing Images
Now, let’s try to resize it to 600X300px. The command is: You can also resize the image to a specific percentage. For example, to scale down “Maketecheasier.png” by 50%, we will use the following command: The resizing method here is not restricted to scaling down only. You can also use it to upscale an image. For example, to double the size of an image: If you want to overwrite the original image, you can use the mogrify command instead. It is similar to the convert command, but it is easier to use and it overwrites the original file.
Batch Resize All Images of a Folder
You can easily resize all images in a particular directory. It lets you bulk resize images to specific dimensions. For instance, there are five images in the “Screenshots” directory, and we want to resize the size of these images by 50%. Therefore, we will run the following commands: Note: Please change the image format from the above command if you are dealing with any other image format rather than JPG.
Change the image format
If you want to change the format of an image, you just have to change the output name to the new format. For example, to convert “Maketecheasier.png” to “Maketecheasier.jpg”, use the following command:
Reduce Image Quality
You can also change the quality of images with ImageMagick. For example, when you take a screenshot on your system, it’s generally captured as a png file in a large size. To reduce the size, you can reduce the screenshot’s quality and convert it into a jpg file:
Rotate Images
To rotate images, all you have to do is use the -rotate option along with the number of degrees you want the image to rotate. For example, the following command creates a 90-degree rotated “screenshot.jpg:”
Create GIF file
If you have a bunch of jpg files and you want to create an animated GIF, ImageMagick can do it too. All you have to do is to load all the jpg files to convert and output it as gif:
Add Watermark to Images
Sometimes you may need to add some text or a logo/graphic to an existing image. For this you use the –append option. In this example, I’m adding a bar to the bottom of my image with a note about the contents.
Remove Exif Data From Image
As a privacy measure, it is sometimes useful to remove all the Exif data from a JPEG photo. You can do it with the mogrify command: