Imagine
Object-oriented PHP image manipulation with a unified API over GD, Imagick, and Gmagick.
Repository Health
Technical Analysis
Imagine is an object-oriented image manipulation library for PHP, inspired by Python’s PIL, that brings the major native image extensions — GD, Imagick, and Gmagick — under one clean, consistent API. This fork, maintained by Pixel & Tonic (the team behind Craft CMS), keeps the well-established library current with modern PHP.
Rather than writing driver-specific code, developers work against a single set of interfaces to load, resize, crop, rotate, filter, draw on, and export images. The same code runs regardless of which underlying imaging extension is installed, making it straightforward to build portable image-processing pipelines.
What You Get
- A single object-oriented API that works across the GD, Imagick, and Gmagick PHP extensions
- Core manipulation tools: resize, crop, rotate, paste, thumbnail, and export in multiple formats
- A drawing API for shapes, lines, text, and other primitives directly on images
- A composable filter and effects system for reusable image transformations
- Masking support for applying grayscale masks to control transparency
- EXIF-aware handling, including autorotation when the PHP exif extension is available
Common Use Cases
- Generating thumbnails and responsive image variants during uploads
- Applying watermarks, overlays, or text captions to user-supplied images
- Building server-side image transformation pipelines for a CMS or web app
- Normalizing image orientation and format across heterogeneous sources
Under The Hood
Architecture - Imagine is organized around a small set of driver-agnostic interfaces (ImagineInterface, ImageInterface, DrawerInterface) implemented separately under src/Gd, src/Imagick, and src/Gmagick. Application code instantiates a concrete Imagine factory for the desired backend, then works entirely through the shared interfaces, so the Image, Draw, Effects, Filter, and Utils namespaces provide backend-independent behavior while each driver subtree adapts to its native extension.
Tech Stack - Pure PHP (99.6% of the codebase) targeting PHP 7.1+, with optional runtime dependence on the GD, Imagick, or Gmagick extensions and the exif extension for metadata. It uses PSR-4 autoloading (Imagine\ => src/) and PHPUnit for testing, with no third-party runtime Composer dependencies.
Code Quality - The repository ships an extensive PHPUnit suite under tests/, organized by driver with test groups for extension-specific behavior and a coding-style workflow enforced via GitHub Actions. Long history (over 1,900 commits, 150+ contributors) and dockerized multi-PHP test matrices indicate mature, well-exercised code.
API Design - The public API is deliberately small and PIL-inspired: obtain an Imagine instance, open or create an image, and chain manipulation calls. Naming is consistent across drivers and the interface-first design keeps boilerplate minimal, though callers must know which imaging extension is installed to pick the right factory.