Install ImageMagick (Image Manipulation) Tool on RHEL, CentOS and Fedora


Introduction

ImageMagick is a powerful open-source software suite used for image manipulation, editing, and conversion. It supports a wide range of image formats and provides a comprehensive set of command-line tools for performing various image-related tasks. In this article, we will guide you through the process of installing ImageMagick on RHEL (Red Hat Enterprise Linux), CentOS, and Fedora systems. We will also provide several examples demonstrating the usage of ImageMagick commands.

Step 1: Update the System

Before installing any software, it is recommended to update your system to ensure you have the latest package information. Open a terminal and run the following command −

sudo dnf update

Step 2: Install ImageMagick

Once the system is up-to-date, you can proceed with installing ImageMagick. Run the following command −

sudo dnf install ImageMagick

The package manager will download and install ImageMagick along with its dependencies.

Step 3: Verify the Installation

To confirm that ImageMagick has been installed successfully, run the following command −

magick -version

You should see the version information and other details about ImageMagick displayed on the terminal.

Example Usage

Convert an Image Format

To convert an image from one format to another, use the convert command. For example, let's convert a PNG image to JPEG −

convert input.png output.jpg

This command takes the input.png file and converts it to output.jpg in JPEG format.

Resize an Image

ImageMagick allows you to resize images easily. Let's resize an image to a specific width and height −

convert input.jpg -resize 800x600 output.jpg

This command resizes the input.jpg file to a width of 800 pixels and a height of 600 pixels and saves the result as output.jpg.

Apply Image Effects

You can apply various effects to images using ImageMagick. For example, let's apply a blur effect −

convert input.jpg -blur 0x8 output.jpg

This command applies a Gaussian blur with a radius of 8 pixels to the input.jpg file and saves the result as output.jpg.

Crop an Image

You can crop an image to extract a specific portion. Let's crop an image to a specific width and height −

convert input.jpg -crop 400x300+100+50 output.jpg

This command crops the input.jpg file to a width of 400 pixels and a height of 300 pixels, starting at coordinates (100, 50), and saves the result as output.jpg.

Rotate an Image

ImageMagick allows you to rotate images. Let's rotate an image by a specific angle −

convert input.jpg -rotate 90 output.jpg

This command rotates the input.jpg file by 90 degrees clockwise and saves the result as output.jpg.

Add Text to an Image

You can add text to an image using ImageMagick. Let's add a text overlay to an image −

convert input.jpg -gravity center -pointsize 24 -draw "text 0,0 'Hello, ImageMagick!'" output.jpg

This command adds the text "Hello, ImageMagick!" at the center of the input.jpg file with a font size of 24 pixels and saves the result as output.jpg.

Create a Thumbnail

ImageMagick allows you to generate thumbnails of images. Let's create a thumbnail of a specific size −

convert input.jpg -thumbnail 200x200 output.jpg

This command creates a thumbnail of the input.jpg file with a maximum size of 200x200 pixels and saves it as output.jpg.

Apply Image Filters

You can apply various filters to enhance or modify images. Let's apply a sepia tone filter −

convert input.jpg -sepia-tone 80% output.jpg

This command applies a sepia tone filter to the input.jpg file with a strength of 80% and saves the result as output.jpg.

Merge Images

ImageMagick allows you to merge multiple images into a single image. Let's merge two images horizontally −

convert image1.jpg image2.jpg +append output.jpg

This command horizontally appends image2.jpg to the right of image1.jpg and saves the merged image as output.jpg.

Create an Image Collage

You can create image collages by combining multiple images into a grid. Let's create a 2x2 image collage −

convert image1.jpg image2.jpg image3.jpg image4.jpg -tile 2x2 -geometry +10+10 output.jpg

This command combines image1.jpg, image2.jpg, image3.jpg, and image4.jpg into a 2x2 grid, with a 10-pixel gap between each image, and saves the collage as output.jpg.

Convert Image to Grayscale

ImageMagick allows you to convert an image to grayscale. Let's convert an image to grayscale −

convert input.jpg -colorspace Gray output.jpg

This command converts the input.jpg file to grayscale and saves the result as output.jpg.

Create a GIF Animation

You can use ImageMagick to create GIF animations from a series of images. Let's create a GIF animation from multiple image files −

convert frame1.png frame2.png frame3.png -delay 100 -loop 0 animation.gif

This command combines frame1.png, frame2.png, and frame3.png into an animated GIF with a delay of 100 milliseconds between frames and saves it as animation.gif.

Apply Image Masking

ImageMagick allows you to apply image masks to reveal or hide specific portions of an image. Let's apply an image mask −

convert input.jpg mask.png -alpha off -compose CopyOpacity -composite output.jpg

This command applies mask.png as an alpha mask to input.jpg, revealing only the portions defined by the mask, and saves the result as output.jpg.

These additional examples demonstrate further capabilities of ImageMagick for merging images, creating collages, converting to grayscale, creating GIF animations, and applying image masks. Experiment with these commands and explore the vast possibilities offered by ImageMagick to enhance and manipulate your images according to your creative vision.

Conclusion

ImageMagick is a versatile tool for image manipulation and editing. In this article, we provided a step-by-step guide to installing ImageMagick on RHEL, CentOS, and Fedora systems. We also demonstrated some of the basic commands for image conversion, resizing, and applying effects. With ImageMagick, you have a powerful set of tools at your disposal to manipulate images according to your requirements.

Updated on: 17-Jul-2023

268 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements