Skip to main content

ImageMagick

ImageMagick is a powerful image manipulation library which we use in Files Gallery for the following:

  • Convert HEIC HEIF PSD TIFF and DNG images to browser-friendly JPG format.
  • Create thumbnails for PDF documents.
  • Create thumbnails for all images when image_resize_use_imagemagick is enabled.

Although ImageMagick is optional, it must be installed and available on your server for the above features to work. In many cases, ImageMagick may already be installed on your server and available from CLI or through the PHP Imagick extension.

1. ImageMagick CLI

In many cases, ImageMagick will be installed on your server already, available from CLI (command-line interface). PHP exec() function must be enabled for Files Gallery to be able to interact with the CLI. You can install ImageMagick on Ubuntu/Debian with apt install imagemagick or on macOS with brew install imagemagick.

ImageMagick path

When using ImageMagick CLI, you may need to adjust the imagemagick_path config option.

'imagemagick_path' => 'magick', // default for ImageMagick version 7 and higher
'imagemagick_path' => 'convert', // ImageMagick version 6 and lower, but will work with newer versions also

2. PHP Imagick Extension

PHP Imagick is an extension that provides integration with ImageMagick directly from PHP. On Ubuntu/Debian, it can be installed with apt install php-imagick.


ImageMagick image types

By default, ImageMagick is assigned to convert image formats HEIC HEIF PSD TIFF and DNG. If you require additional formats, you can use the imagemagick_image_types config option.

'imagemagick_image_types' => 'heif, heic, tiff, tif, psd, dng',

Resize images with ImageMagick

When ImageMagick is enabled, you have the option to use image_resize_use_imagemagick to force all thumbnails to be created by ImageMagick instead of the default PHP GD. Advantages may be better performance (especially with very large images) and better memory management (will not crash due to insufficient memory).

'image_resize_use_imagemagick' => true, // true | false

PDF support in ImageMagick

PDF is a special format which requires Ghostscript. In most cases, Ghostscript will be installed when ImageMagick is installed, although in some cases it will be missing, in which case PDF thumbnails are not supported.

HEIC image support with Cloudflare

If you can't install ImageMagick, your remaining option is to convert images with Cloudflare Images. Cloudflare image transformation is free for up to 5,000 unique conversions every month.

  1. Your website must be using Cloudflare.
  2. Enable transformations on your zone.
  3. Enable cloudflare_convert from Javascript config.