If this is your first time hearing of Intervention Image, it's a powerful PHP package that provides an easy and expressive way to edit images. The library supports PHP's most familiar image processing libraries: GD Library, Imagick, or libvips. It has been a while since we last covered Intervention Image v2, but developer Oliver Vogel has improved the package significantly. Version 3 has been completely rewritten from the ground up, featuring new capabilities, a more modern and sophisticated architecture, and an API that takes full advantage of the modern features of PHP 8+.
Key Features
The key features of this package are:
- Unified API for Multiple Drivers: Switch seamlessly between GD, Imagick, or libvips while maintaining the same code structure.
- Powerful Resizing Options: Resize, crop, fit, and scale images with precision.
- Image composition: Position images on top of other images, adjust offsets, and control opacity for custom overlays or watermarks
- Draw Geometric Shapes on Images: Create and manipulate shapes including rectangles, circles, ellipses, lines, and polygons with customizable borders, fills, and styling.
- Animated Image Support: Process GIF and other animated image formats with frame-by-frame manipulation capabilities.
- Support for colorspaces and profiles: Work with various colorspaces and ICC profiles to ensure color accuracy across different media and output formats.
- Text and Font Support: The font system supports text wrapping, line height customization, and advanced typographic controls, making it suitable for generating dynamic text-based graphics.
Example
use Intervention\Image\ImageManager; // create image manager with desired driver$manager = new ImageManager( new Intervention\Image\Drivers\Gd\Driver()); // open an image file$image = $manager->read('images/featured-image.jpg'); $image->resize(height: 1100); $image->place('images/LN-watermark.png'); $encoded = $image->toPng(); $encoded->save('images/featured-article-image.png');
Give it a try by installing the package using Composer:
composer require intervention/image
Read the official documentation to learn more about this package and view the source code on GitHub.