Imagick
Provides an image toolkit implementation based on the PHP Imagick extension for advanced image manipulation within Drupal.
imagick
Install
composer require 'drupal/imagick:8.x-1.12'
composer require 'drupal/imagick:8.x-1.11'
Overview
The Imagick module provides an alternative image toolkit for Drupal that uses the PHP Imagick extension (ImageMagick) instead of GD for image processing. Unlike the ImageMagick module which invokes the convert binary via command line, this module uses the Imagick PHP extension directly, enabling custom effects that need direct access to image data such as Smart Crop.
The module offers over 30 image effects that can be applied to image styles, ranging from basic operations like blur and sharpen to advanced effects like polaroid, charcoal, and oil painting. It includes JPEG optimization following Google PageSpeed guidelines, configurable resize filters, and metadata stripping capabilities.
The Imagick toolkit supports all image formats that ImageMagick supports, providing much broader format support compared to the default GD toolkit. This makes it ideal for sites that need to handle diverse image formats or require advanced image manipulation capabilities.
Features
- Alternative image toolkit using PHP Imagick extension for direct image data access
- Over 30 configurable image effects for image styles including blur, sharpen, polaroid, charcoal, oil painting, and more
- JPEG optimization following Google PageSpeed Insights guidelines for improved performance
- Configurable resize filters with 16 different filter options for optimal image quality
- Automatic metadata stripping to reduce file size and remove sensitive EXIF data
- Support for animated GIF and WebP images with multi-frame handling
- Image encryption and decryption using password-protected enciphering
- Color picker interface for effects requiring color selection
- Custom convolution kernel matrix for advanced image filtering
- Automatic image rotation based on EXIF orientation data
Use Cases
Creating Professional Image Styles
Use Imagick effects to create sophisticated image styles for a photography portfolio. Apply combinations of effects like vignette for artistic borders, sharpen for crisp details, and colorshift for consistent color grading across all uploaded images.
Watermarking Images
Use the Annotate effect to add text watermarks to images, or use the Composite effect to overlay a logo image on uploaded photos. Configure position, opacity, and blend modes for professional watermarking.
Creating Artistic Thumbnails
Generate artistic thumbnail variations using effects like Charcoal for sketch-style thumbnails, Oilpaint for painterly effects, or Polaroid for vintage-style photo frames.
Optimizing JPEG Images
Enable Google PageSpeed optimization to automatically compress JPEGs with optimal sampling factors, RGB colorspace, and progressive interlacing for faster page loading without significant quality loss.
Handling EXIF Orientation
Use the Autorotate effect to automatically correct image orientation based on EXIF data, ensuring photos from smartphones and cameras display correctly regardless of how they were taken.
Creating Transparent Background Images
Use the Transparent Background effect combined with Trim to remove solid backgrounds from product images, creating clean cutouts for e-commerce catalogs.
Securing Sensitive Images
Use the Encipher effect to encrypt sensitive images with a password, then use Decipher in another image style to decrypt them for authorized viewing.
Reducing PNG File Size
Apply the Posterize effect to reduce color levels in PNG images, significantly decreasing file size while maintaining acceptable visual quality for web graphics.
Tips
- For best JPEG quality, keep the quality setting at 80% or higher and enable Google PageSpeed optimization
- Use the Convert effect as the last effect in an image style to control the final output format and quality
- The Strip effect can significantly reduce file sizes by removing EXIF, ICC profiles, and other metadata
- When combining multiple blur or sharpen effects, start with smaller values and increase gradually
- Use the Define Canvas effect to add consistent borders or prepare images for composite operations
- The Convolve effect accepts a 3x3 kernel matrix - search online for common convolution kernels for effects like edge detection or sharpening
- Enable metadata stripping globally in toolkit settings to automatically remove EXIF data from all processed images
Technical Details
Admin Pages 2
/admin/config/media/image-toolkit
Configure the image toolkit settings. When Imagick is selected, additional configuration options become available for JPEG quality, optimization, resize filters, and metadata handling.
/admin/config/media/image-styles
Configure image styles and add Imagick-specific effects. When Imagick toolkit is enabled, additional effects become available in the effect list.
Troubleshooting 5
Ensure the PHP Imagick extension is installed and enabled. Check with phpinfo() or run 'php -m | grep imagick' on the command line.
Check Drupal's watchdog logs for detailed error messages. Ensure the Imagick PHP extension version is compatible and all required ImageMagick components are installed.
The module handles animated GIFs using coalesceImages() and writeImages(). Ensure these operations are supported by your ImageMagick installation.
Check the colorspace settings. Enable the Google PageSpeed optimization which sets RGB colorspace, or manually ensure consistent colorspace handling.
Large images may exceed PHP memory limits. Increase memory_limit in php.ini or consider using the ImageMagick module which uses command-line processing for better memory handling.
Security Notes 3
- The Encipher/Decipher effects store passwords in configuration - ensure proper access controls on configuration export
- Stripping metadata removes EXIF data including GPS coordinates which may be a privacy concern for user-uploaded images
- Image processing can be resource-intensive - consider rate limiting or access controls for image style generation on public sites