php-imagine/Imagine: a driver-neutral image API for PHP
PHP Object Oriented image manipulation library
At a glance
- What is it?
- Imagine wraps GD2, Imagick and Gmagick behind one object-oriented API for resizing, cropping, drawing and masking, so the same code runs on whichever extension a host happens to have. The catch is that the drivers are not interchangeable in practice.
- Who is it for?
- Adopt Imagine if you need driver-neutral image code in PHP 7.1 or newer and you can pin one backend in production. Do not adopt it if you need multi-layer formats such as PSD through the GD driver, or if your pipeline depends on PHP 5.x, which the README maps to the 1.2 and 1.3 lines rather than the current release.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 118 days ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 30, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The problem Imagine solves in a PHP codebase
PHP has three common image extensions, and they do not share an API. GD2 has one set of function names, Imagick is a class-based wrapper around ImageMagick, and Gmagick is a third, similar but distinct class tree. Code written against one does not run against the others, so a library that ships to shared hosting and to a container with different extensions usually ends up with two or three code paths, or with a hard requirement on one extension that some hosts do not have.
Imagine's stated purpose is to bring those native libraries to "the same simple and intuitive OO API". The README frames the library as inspired by Python's PIL and other image libraries. The audience is PHP developers who need resize, crop, drawing and masking in application code and do not want the choice of backend to leak into their business logic. A CMS plugin, a thumbnail service or an avatar pipeline is the kind of code this fits.
One API, three drivers, and where the abstraction leaks
The design is a facade over the extensions. You pick an implementation, then call the same methods regardless of which one you picked. The README lists three capabilities the API is meant to cover: image manipulation tools such as resize and crop, a drawing API for basic shapes, advanced charts and text, and masking, where a black-and-white or grayscale image is applied as a mask to produce semi-transparency or full transparency in the target image.
Filters sit on top of those primitives. The README describes filters as a more powerful layer built from the manipulation, drawing and masking tools, and lists ideas for upcoming ones: charting and graphing filters such as pie and bar charts and linear graphs with annotations, an Apple-style reflection, and rounded corners. Note the wording: those are described as ideas for upcoming filters, not as shipped features, so treat them as a direction rather than an inventory.
The abstraction is not total. The README's contributing notes say some PHPUnit tests are skipped when a driver does not support multiple layers and the suite is executed with the GD driver. That is a direct admission that layer support differs by backend, which matters if you work with layered formats. The README also notes that gmagick tests are skipped when gmagick is not installed. So the uniform API is real for the common operations, and conditional for the advanced ones.
Installing Imagine and producing your first resized image
Installation is through Composer. The README gives the command as follows, and it pulls in the library plus its Composer metadata:
php composer.phar require imagine/imagineThe README states the requirement as PHP 7.1 or newer. Older PHP versions are served by older lines: PHP 5.5 to 7.0 use version ^1.3, and PHP 5.3 to 5.4 use version ^1.2. Depending on the implementation you choose, you need GD2, Imagick, or Gmagick installed. For Imagick the README specifies ImageMagick 6.2.9 or later, except version 7.0.7-32, which is called out as an exclusion.
EXIF handling is separate. The README says to activate the PHP exif extension to read EXIF metadata, for example for autorotation. It also says Imagine works without it, but then it cannot read or act on image orientation or other EXIF metadata. That is the difference between an uploaded photo landing upright and landing sideways, so check the extension before blaming the library.
A typical first use is opening a file, resizing it, and saving it. The documentation hosted at imagine.readthedocs.io is where the API surface is described, and the README points there rather than inlining examples. What you should expect after the Composer command is a vendor directory containing the library and an autoloader entry for it; after a resize call, a new image file on disk at the dimensions you asked for.
Driver parity is the real limitation, not the API
The most concrete constraint in the README is the test-skipping policy. Tests that require a driver supporting multiple layers are skipped when the suite runs with GD. If your work involves layered images, GD is the wrong backend and the library will not paper over that. Similarly, gmagick tests are skipped without gmagick installed, which means a GD-and-Imagick environment simply does not exercise that code path.
This has a practical consequence for deployment. If you develop against Imagick and deploy where only GD is available, the shared subset of the API will work and the layered operations will not. The repository's own test setup reflects this: the README recommends the prebuilt docker images so that a contributor can run the suite against a specific combination, for example PHP 8.1 with both GD and Imagick. The command given is:
docker run --rm -it -v /home/me/imagine:/app -w /app ghcr.io/php-imagine/test:8.1-gd-imagick bashInside that container the README starts a local web server on port 8013 because some tests require one, exports IMAGINE_TEST_WEBSERVERURL as http://localhost:8013, runs composer update, and then runs the suite while excluding the always-skipped and gmagick groups:
composer run test -- --exclude-group always-skipped,gmagickThe Windows note in the README swaps the volume path for a Windows path such as C:\Path\To\Imagine. A second environment variable, IMAGINE_TEST_KEEP_TEMPFILES, keeps the temporary images that tests normally write to tests/tmp and then delete, which is useful when you want to inspect what a filter actually produced. None of this is a runtime limitation, but it tells you the maintainers consider the driver matrix the hard part of the project.
Where Imagine is the wrong tool
If your application only ever runs on one host with one known extension, the facade buys you less than it costs. You are adding a dependency and an indirection layer to reach functions you could call directly, and the abstraction will still leak on layered formats. In that situation the native extension is the shorter path.
Imagine is also the wrong choice for anything that is not raster image manipulation in PHP. It is not a video pipeline, not a document renderer, and not a replacement for a dedicated image service if you are resizing at a scale where you would otherwise hand the work to a CDN or a separate process. The README describes a library, not a service.
Finally, PHP version is a hard boundary. If you are on PHP 5.3 or 5.4, the README points you at the ^1.2 line; on PHP 5.5 through 7.0, at ^1.3. Those are different codebases from the current release, so advice written against the current documentation may not apply to you.
How Imagine differs from calling GD or Imagick directly
The direct alternative is the native extension itself. Calling GD functions or instantiating Imagick classes directly gives you the full feature set of that extension with no translation layer, and no risk that a method behaves differently on another backend. The difference in approach is that you write against one vendor's API and accept that the code is bound to it.
Imagine inverts that trade. You write once against a common API and accept that the common API is the intersection plus whatever the library can emulate, with the driver-specific gaps documented as skipped tests. For a project that ships to heterogeneous hosting, that is a reasonable trade. For a project with a fixed runtime, it is an extra layer.
A second alternative is the broader ImageMagick command line, invoked as a subprocess. That moves the work outside PHP entirely and gives you ImageMagick's full operator set, at the cost of process management, temporary files and shell escaping. Imagine keeps the work in-process and in PHP objects, which is easier to test with PHPUnit but bounded by what the extensions expose.
Maintenance, releases and what the licence file does not say
The repository is not archived and the last push was on 2026-06-04, the same day as the 1.5.4 release. The releases before it are 1.5.3 on 2026-06-03 and 1.5.2 on 2026-01-09, so the current line has seen patch releases this year. The default branch is develop, and the README is explicit about the branch policy: new pull requests should be based on develop, while master is the stable branch that usually matches the latest release but can be a bit ahead. If you vendor from a branch rather than a tagged release, that is the branch to know about.
The licence field reports NOASSERTION, meaning the automated classifier did not map the LICENSE file to a known SPDX identifier. The repository does contain a LICENSE file at the top level, so the terms exist and are readable, but they are not summarized here and this is not legal advice. Read that file yourself before shipping the library in a product, particularly if you redistribute it.
Upgrade cost is mostly the PHP floor. The README ties release lines to PHP versions, so moving from PHP 7.0 to 7.1 or newer is what lets you take the current line. Beyond that, the driver matrix is the thing to re-test: a PHP upgrade that changes which extensions are available will change which code paths your tests actually exercise.
Editorial conclusion
Adopt Imagine if you need driver-neutral image code in PHP 7.1 or newer and you can pin one backend in production. Do not adopt it if you need multi-layer formats such as PSD through the GD driver, or if your pipeline depends on PHP 5.x, which the README maps to the 1.2 and 1.3 lines rather than the current release. Before committing, verify three things on your own images: which extension your host actually has, whether the exif extension is loaded if you rely on autorotation, and whether your target format needs a driver other than GD. The repository is not archived and the last push was on 2026-06-04.
Frequently asked questions
What is php-imagine/Imagine?
It is a PHP object-oriented image manipulation library, described in its README as inspired by Python's PIL and other image libraries. It puts GD2, Imagick and Gmagick behind one API for manipulation, drawing and masking.
How do I install Imagine in a PHP project?
The README gives the Composer command php composer.phar require imagine/imagine. The stated requirement is PHP 7.1 or newer, plus one of GD2, Imagick or Gmagick depending on the implementation you choose.
Which PHP extensions does Imagine need?
Depending on the chosen implementation, one of GD2, Imagick or Gmagick. For Imagick the README specifies ImageMagick 6.2.9 or later, except version 7.0.7-32. The exif extension is optional but required for reading orientation and other EXIF metadata.
Does Imagine work without the exif extension?
Yes. The README states Imagine works without the PHP exif extension, but then it cannot read and act on image orientation or other EXIF metadata, which is what autorotation depends on.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/php-imagine-imagine)