How to Install ImageMagick on Ubuntu 24.04, 22.04, or 20.04

ImageMagick is a powerful open-source software suite used for image manipulation, conversion, and editing. It supports over 200 image formats, making it an indispensable tool for developers, graphic designers, and system administrators. ImageMagick can be used for tasks such as resizing, cropping, flipping, and applying various effects to images, all through command-line operations, which makes it highly versatile for automation and batch processing.

On Ubuntu 24.04, 22.04, or 20.04, you can install ImageMagick via two main methods. The first method is through the Ubuntu default repository, which offers a stable version that is easy to install and integrates seamlessly with your system’s package management. The second method involves downloading and compiling the latest ImageMagick source binary. This approach allows you to install the most recent build, ensuring you have access to the latest features and improvements, though it requires more technical steps. This guide will walk you through both installation methods, allowing you to choose the best option based on your needs.

Method 1: Install ImageMagick via APT

Update Ubuntu Before ImageMagick Installation

The first step in installing ImageMagick on Ubuntu is ensuring your system is up to date. This will ensure that you have the latest security updates and that your system is compatible with ImageMagick.

To update your system, open the terminal and run the following command:

sudo apt update && sudo apt upgrade

Install Support Libraries For ImageMagick

ImageMagick relies on several libraries to function correctly. To install these libraries, run the following command:

sudo apt install libpng-dev libjpeg-dev libtiff-dev

Install ImageMagick on Ubuntu via APT Command

The easiest and most recommended way for the average user to install ImageMagick is through the APT package manager. If this works correctly, stick with it; do not try to install the source method, as it will complicate things more than you need.

For the APT method, install ImageMagick using the following command:

sudo apt install imagemagick

And that is it; for alternative installation methods, see the next section on compiling ImageMagick.

Method 2: Install ImageMagick via Source

The alternate installation method involves cloning the ImageMagick GIT repository and compiling the application. This option is not suitable for the average user. However, follow these steps to utilize the source version to access the latest or a specific older release.

Ensure Git is Installed

Before proceeding with this installation method, you must ensure that GIT is installed on your system. You can check this by running the following command in the terminal:

git --version

The command shows the GIT version installed on your system. If you don’t have GIT, run the following command to install it:

sudo apt install git

Clone ImageMagick Git Repository

Open the terminal, navigate to the desired location to store the cloned repository, and then run the following command to clone the repository:

git clone https://github.com/ImageMagick/ImageMagick.git

If you prefer, you can specify the location of the cloned repository to “/usr/local/src/ImageMagick” by using the following command:

git clone https://github.com/ImageMagick/ImageMagick.git /usr/local/src/ImageMagick

It’s important to note that depending on your GIT/user privilege configuration, you may use the sudo command while cloning the repository:

sudo git clone https://github.com/ImageMagick/ImageMagick.git /usr/local/src/ImageMagick

Navigate to ImageMagick Source Directory

Clone the ImageMagick repository, then navigate to the directory where you cloned it. The location might differ based on your specific setup, but here are the general steps:

cd ImageMagick

Or if you cloned it to “/usr/local/src/ImageMagick.”

cd /usr/local/src/ImageMagick

Install Required Packages to Compile ImageMagick

To continue the installation process, you must install the dependencies required to compile ImageMagick. The dependencies include various libraries and tools necessary for the compilation process. You can install the dependencies by running the following command in the terminal:

sudo apt install build-essential libltdl-dev libjpeg-dev libpng-dev libtiff-dev libgif-dev libfreetype6-dev liblcms2-dev libxml2-dev

Prepare the ImageMagick Source

With the dependencies installed, the next step is to run the ./configure command to prepare the ImageMagick source for compilation:

./configure

This command will check for any dependencies or configurations required to compile ImageMagick. The ./configure command will display an error message if any dependencies or configurations are missing. In this case, you must install the missing dependencies or resolve the configuration issues before proceeding with the next step.

Optional: Configure ImageMagick with Modules

Advanced users who want more functionality from ImageMagick should build the application using the –with-modules option. This option allows the installation of extra optional features and modules, enhancing the ImageMagick experience.

To use this option, include it in the ./configure command:

./configure --with-modules

Note: By including “./configure—-with-modules,” you can ensure access to ImageMagick’s full range of features and functionality.

Build ImageMagick Environment

After building and configuring the environment, compile ImageMagick using the make command:

make

This command will compile the ImageMagick source code into a usable application. The compilation process may take several minutes, depending on your system specifications. After the compilation is complete, you can proceed with the next step.

Install ImageMagick via Compiled Binary

With the source code compiled, the next step is to run the installation command. This will install ImageMagick on your Ubuntu system:

sudo make install

Configure Dynamic Linker Run-Time for ImageMagick

After installing ImageMagick, configure the dynamic linker run-time bindings as the final step. This action ensures your system can find and use the ImageMagick libraries during run-time:

sudo ldconfig /usr/local/lib

This command will configure the dynamic linker run-time bindings, making ImageMagick accessible and usable on your system.

After running this command, you should be able to use ImageMagick without any issues; failure may result in the following error in your terminal:

magick: error while loading shared libraries: libMagickCore-7.Q16HDRI.so.10: cannot open shared object file: No such file or directory

Remember that if you upgrade or reinstall ImageMagick in the future, you might need to reconfigure the dynamic linker run-time bindings. If that happens, follow the steps above to reconfigure them.

Verify ImageMagick Installation

Once you have installed ImageMagick, you can verify the installation by running the following command.

magick --version

Example output:

Version: ImageMagick x.x.x

Examples of ImageMagick Commands

Convert an Image Format with ImageMagick

ImageMagick can also convert an image from one format to another. For example, you can use the following command to convert a JPG image to PNG.

convert input.jpg output.png

Create a Thumbnail with ImageMagick

Use ImageMagick to create a thumbnail from an image. The command is:

convert input.png -thumbnail 200x200 output.png

This command will create a 200×200 thumbnail from the image “input.png” and save the result as “output.png.”

Resize an Image with ImageMagick

You can use ImageMagick to resize an image to a specific dimension. The command for this is.

convert input.png -resize 200x200 output.png

This will resize the image “input.png” to a 200×200 image and save the result as “output.png.”

Add Text to an Image with ImageMagick

You can add text to an image using ImageMagick. The command for this is.

convert input.png -font Arial -pointsize 36 -fill black -draw "text 20,50 'Hello World'" output.png

This command adds the text “Hello World” to the image “input.png” using the Arial font and a 36-point font size. The text has a black fill and sits at the position (20,50). The system saves the result as “output.png.”

Conclusion

By installing ImageMagick on your Ubuntu system using either the default repository or by compiling the source binary, you gain access to a comprehensive toolset for image processing. The repository method offers ease of use and stability, while compiling from source provides the latest features and customizations. Regular updates, especially when using the source method, will keep your ImageMagick installation current, enabling you to perform advanced image manipulation tasks efficiently on Ubuntu.

Useful Links

Here are some useful links related to using ImageMagick on an Ubuntu system:

  • ImageMagick GitHub Repository: Visit the official ImageMagick GitHub repository to access the source code, report issues, and contribute to the development.
  • ImageMagick Official Website: Explore the official ImageMagick website for detailed information about the software, its features, and the latest updates.
  • ImageMagick Discussions: Join the discussions on GitHub to ask questions, share solutions, and get support from the ImageMagick community.

Leave a Comment