ImageMagick lets you resize, crop, convert, and batch-process images directly from the command line. Ubuntu does not include ImageMagick by default, so you must install it through the package manager or compile from source. Common use cases include converting hundreds of JPG files to PNG for web optimization, generating thumbnails automatically for galleries, and adding watermarks to protect images. By the end of this guide, you will have a working ImageMagick installation ready for format conversion, batch resizing, and automated image transformation tasks.
Choose Your ImageMagick Installation Method
Ubuntu offers multiple ways to install ImageMagick. Generally, the APT method provides a stable, distribution-tested version with automatic updates, while compiling from source gives you access to the latest features and bug fixes.
| Method | Channel | Stability | Best For |
|---|---|---|---|
| APT Package | Official repos | Stable | Most users who want easy installation and automatic updates |
| Compile from Source | Source (GitHub) | Latest features | Developers who need cutting-edge features or custom builds |
For most users, the APT package provides sufficient functionality with minimal maintenance. Choose the source compilation method only if you specifically need features not yet available in the Ubuntu package.
Method 1: Install ImageMagick via APT
The APT method installs ImageMagick 6.x from Ubuntu’s official repositories. As a result, you get a stable version with automatic security updates and minimal maintenance requirements.
Install ImageMagick Package
First, update your package lists and install ImageMagick along with common image format libraries:
sudo apt update && sudo apt install imagemagick libpng-dev libjpeg-dev libtiff-dev
Verify APT Installation
Next, confirm ImageMagick installed correctly by checking the version:
convert --version
As a result, you should see output similar to:
Version: ImageMagick 6.9.12-98 Q16 x86_64 18420 https://imagemagick.org Copyright: (C) 1999 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC Modules OpenMP(4.5) Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
The Ubuntu repository provides ImageMagick 6.x, which uses separate commands like
convert,identify, andmogrify. If you need ImageMagick 7 with the unifiedmagickcommand and latest features, use the source compilation method in the next section.
Method 2: Install ImageMagick from Source
Compiling from source installs ImageMagick 7, which uses the unified magick command instead of the legacy convert, identify, and other separate utilities. However, this method requires additional steps but provides access to the latest features and performance improvements.
Install Build Dependencies
First, install the compiler toolchain and development libraries required for compilation:
sudo apt install build-essential git pkg-config libltdl-dev libjpeg-dev libpng-dev libtiff-dev libgif-dev libfreetype6-dev liblcms2-dev libxml2-dev
This installs GCC and essential build tools along with image format libraries for JPEG, PNG, TIFF, and GIF support. The
pkg-configpackage is required for the configure script to locate delegate libraries correctly. If you need to install or upgrade Git on Ubuntu, do so before proceeding.
Clone the Repository
Next, download the ImageMagick source code from the official GitHub repository. For production systems, clone a specific release tag rather than the development branch:
git clone --depth 1 --branch 7.1.1-43 https://github.com/ImageMagick/ImageMagick.git
cd ImageMagick
The
--depth 1flag creates a shallow clone without full history, reducing download size significantly. The--branchflag specifies a stable release tag. Check the releases page for the latest stable version and substitute accordingly. Version numbers in this guide are examples current at the time of writing. For development work, omit the branch flag to clone the latest code.
Configure the Build
Then, run the configure script to detect your system configuration and prepare the build:
./configure --with-modules
The --with-modules flag enables dynamic loading of image format coders, which allows ImageMagick to support additional formats without recompilation. Additionally, the script checks for available libraries and displays a summary of enabled features.
A successful configuration ends with output similar to:
ImageMagick is configured as follows: ... Host system type: x86_64-pc-linux-gnu Build system type: x86_64-pc-linux-gnu Option Value --------------------------------------------------------------- Shared libraries --enable-shared=yes yes Static libraries --enable-static=yes yes Module support --with-modules=yes yes
Compile and Install ImageMagick
Now, compile ImageMagick using all available CPU cores to speed up the build:
make -j$(nproc)
The compilation takes several minutes depending on your system. Afterward, you can optionally run the test suite to verify the build before installation:
make check
The
make checktest suite validates ImageMagick’s core functionality. Some tests require Ghostscript and FreeType to pass completely. Minor test failures typically do not affect normal usage; check the Advanced Linux Source Installation guide for troubleshooting specific failures.
Finally, when ready, install ImageMagick system-wide:
sudo make install
Subsequently, verify the installation created the necessary files:
ls /usr/local/bin/magick
You should see:
/usr/local/bin/magick
Update Library Cache
Next, configure the dynamic linker to find the new ImageMagick libraries:
sudo ldconfig /usr/local/lib
The ldconfig command refreshes the shared library cache so your system can find the newly installed ImageMagick libraries. Without this step, you will encounter “cannot open shared object file” errors when running ImageMagick commands.
Verify Source Installation
Finally, confirm the installation by checking the version and performing a quick test conversion:
/usr/local/bin/magick --version
You should see ImageMagick 7.x output:
Version: ImageMagick 7.1.1-43 Q16-HDRI x86_64 22341 https://imagemagick.org Copyright: (C) 1999 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC HDRI Modules OpenMP(4.5) Delegates (built-in): bzlib fontconfig freetype jng jpeg lcms ltdl lzma png tiff webp xml zlib
Additionally, test the installation with a quick image conversion using the built-in logo:
/usr/local/bin/magick logo: logo.gif && ls -la logo.gif
You should see a new logo.gif file created (approximately 27KB):
-rw-rw-r-- 1 user user 27055 Nov 29 12:00 logo.gif
Furthermore, check which image formats are available in your installation:
magick identify -list format | head -30
The format list and delegate list vary depending on which optional libraries were detected during configuration. ImageMagick supports over 200 image formats. Common variations include additional support for HEIC, JXL, or PDF formats if their respective development libraries are installed.
Troubleshoot Installation Issues
Library Loading Errors
If you see a shared library error when running ImageMagick commands after source installation, the dynamic linker cannot find the ImageMagick libraries. This typically happens because source installations place libraries in /usr/local/lib, which may not be in your system’s default library search path.
The error looks like:
magick: error while loading shared libraries: libMagickCore-7.Q16HDRI.so.10: cannot open shared object file: No such file or directory
To resolve this, first verify the library files exist:
ls /usr/local/lib/libMagick*
You should see the ImageMagick library files listed:
/usr/local/lib/libMagickCore-7.Q16HDRI.so.10 /usr/local/lib/libMagickCore-7.Q16HDRI.so.10.0.0 /usr/local/lib/libMagickWand-7.Q16HDRI.so.10 /usr/local/lib/libMagickWand-7.Q16HDRI.so.10.0.0 /usr/local/lib/libMagick++-7.Q16HDRI.so.5 /usr/local/lib/libMagick++-7.Q16HDRI.so.5.0.0
Then, run the ldconfig command to update the library cache:
sudo ldconfig /usr/local/lib
Afterward, verify the fix by checking the version again:
magick --version
Missing Delegate Libraries
If certain image formats fail to process, the required delegate library may not have been detected during configuration. To diagnose this, use grep to check which delegates are compiled in:
magick identify -list configure | grep DELEGATES
Common missing delegates and their packages:
- HEIC/HEIF: Install
libheif-dev - WebP: Install
libwebp-dev - PDF/PS: Install
ghostscriptandlibgs-dev - RAW: Install
libraw-dev
After installing additional libraries, you must reconfigure and rebuild ImageMagick to enable support.
Configure Resource Limits
ImageMagick uses memory, disk, and CPU resources when processing images. To understand your system’s configuration, view your current resource limits:
magick identify -list resource
You should see output similar to:
Resource limits: Width: 100MP Height: 100MP Area: 25.181GB Memory: 11.726GiB Map: 23.452GiB Disk: unlimited File: 768 Thread: 12 Time: unlimited
For batch processing large images or running ImageMagick on a web server, configure limits to prevent resource exhaustion:
magick -limit memory 2GiB -limit map 4GiB input.jpg -resize 50% output.jpg
For production environments, configure permanent limits in the
policy.xmlfile. Use the sed command to edit policy values directly from the terminal, or see the Security Policy Guide for detailed configuration options including format restrictions, path controls, and resource constraints.
Process Images with ImageMagick
The commands below use ImageMagick 7 syntax with the unified magick command. If you installed via APT (ImageMagick 6.x), replace magick with convert in the examples below. Both versions support the same image operations with identical syntax for the operations themselves.
Convert Image Formats
Convert a JPG image to PNG format when you need lossless compression or transparency support:
magick input.jpg output.png
ImageMagick automatically detects the output format from the file extension. Consequently, this works with over 200 image formats including WebP, HEIC, PDF, and SVG.
Create Thumbnails
Generate a 200×200 pixel thumbnail while preserving aspect ratio for image previews or galleries:
magick input.png -thumbnail 200x200 thumbnail.png
The -thumbnail option strips metadata and optimizes the image for web use, resulting in smaller file sizes than -resize.
Resize Images
Resize an image to exactly 800×600 pixels when you need precise dimensions regardless of aspect ratio:
magick input.png -resize 800x600! output.png
The exclamation mark forces the exact dimensions, ignoring aspect ratio. In contrast, without it, ImageMagick maintains the original proportions within the specified bounds.
Add Text Watermarks
Overlay text on an image to protect copyright or add attribution:
magick input.png -font Arial -pointsize 36 -fill black -gravity southeast -annotate +10+10 "Copyright 2025" output.png
This places the text in the bottom-right corner with a 10-pixel margin. The -gravity option controls positioning relative to the image edges.
Batch Process Multiple Files
Convert all JPG files in a directory to PNG when migrating image formats for an entire project:
magick mogrify -format png *.jpg
The mogrify subcommand modifies files in place. As a result, the original JPG files remain unchanged while new PNG versions are created alongside them. For more complex batch operations, combine ImageMagick with find -exec to process files matching specific criteria across nested directories. For more examples and advanced techniques, see Examples of ImageMagick Usage.
Remove ImageMagick
Remove APT Installation
If you installed ImageMagick via APT, simply remove it with:
sudo apt remove imagemagick
Alternatively, to also remove configuration files and unused dependencies:
sudo apt purge imagemagick
sudo apt autoremove
Then, verify ImageMagick is removed:
convert --version
As a result, you should see:
Command 'convert' not found, but can be installed with: sudo apt install imagemagick-6.q16
Remove Source Installation
Alternatively, if you compiled from source, navigate to the source directory and run:
cd ImageMagick
sudo make uninstall
Afterward, update the library cache:
sudo ldconfig
Next, verify ImageMagick is removed:
magick --version
Consequently, you should see:
bash: magick: command not found
Finally, you can also delete the cloned source directory to free disk space:
cd ..
rm -rf ImageMagick
Remove Configuration Files
Additionally, both installation methods create system-wide configuration files in /etc/ImageMagick-6/ or /etc/ImageMagick-7/ depending on the version. To remove these:
The following command permanently removes ImageMagick system configuration including security policies. Only proceed if you are completely removing ImageMagick from your system.
sudo rm -rf /etc/ImageMagick-*
Furthermore, user-specific settings may exist in your home directory:
The following command removes any custom ImageMagick policies or settings you may have configured. Skip this step if you want to preserve your customizations for a future reinstall.
rm -rf ~/.config/ImageMagick
Conclusion
You now have ImageMagick installed and ready for image processing tasks. Specifically, the APT installation provides a stable foundation for format conversion and basic editing using the convert command, while the source compilation delivers ImageMagick 7 with the unified magick command and latest features. Additionally, you can extend your workflow by exploring batch processing with shell scripts or integrating ImageMagick with PHP for dynamic image generation in web applications. For photo editing workflows, consider GIMP or Darktable, and for 3D graphics or advanced compositing, explore Blender or Inkscape for vector graphics.
Additional Resources
For more information about ImageMagick:
- ImageMagick GitHub Repository: Access the source code, report issues, and track development.
- ImageMagick Official Website: Browse documentation, command references, and usage examples.
- Security Policy Guide: Configure ImageMagick security settings for production environments.
- Command-Line Processing: Learn the complete anatomy of ImageMagick commands including geometry, operators, and image stacks.
- Supported Formats: Browse the complete list of 200+ image formats with format-specific options and notes.
- Usage Examples: Comprehensive examples for resizing, compositing, animations, distortions, and special effects.
- Community Discussions: Get help and share solutions with other ImageMagick users.