This is the GBLIX fork of mike42/gfx-php. The upstream repository is no longer actively maintained. This fork targets PHP 8.2+ and is available as
gblix/gfx-phpon Packagist.
This library implements input, output and processing of raster images in pure PHP, so that image processing extensions (Gd, Imagick) are not required.
This allows developers to eliminate some portability issues from their applications.
- Format support includes PNG, GIF, BMP and the Netpbm formats.
- Support for scaling, cropping, format conversion and colorspace transformations.
- Pure PHP: This library does not require Gd, ImageMagick or GraphicsMagick extensions.
- Requires PHP 8.2+ (previously PHP 7.0+)
- Full property type declarations across all classes
- Full method return type declarations
- Fixed implicit nullable parameter deprecations (PHP 8.1)
- Fixed dynamic property deprecations (PHP 8.2)
- Fixed
PngHeader::getCompresssion()reading an undeclared property ($this->compresssion→$this->compression) - Replaced deprecated string pseudo-callables with first-class callable syntax
- PHPUnit upgraded to
^11 - Removed
composer.lock(library policy) - Docker support added
- PHP 8.2 or newer
zlibextension, for reading PNG files
Install gblix/gfx-php with Composer:
composer require gblix/gfx-php<?php
use Mike42\GfxPhp\Image;
$img = Image::fromFile('colorwheel256.png');
$img->write('test.gif');All test commands run inside Docker — no local PHP installation required.
Build the image once:
docker build -t gfx-php-test .Run all PHPUnit tests (unit + integration):
docker run --rm gfx-php-testRun only the unit tests:
docker run --rm gfx-php-test php vendor/bin/phpunit --testsuite unitRun only the integration tests (reads real image files from test/resources/):
docker run --rm gfx-php-test php vendor/bin/phpunit --testsuite integrationRun benchmarks (PHPBench, scale/convert/codec operations):
docker run --rm gfx-php-test php vendor/bin/phpbench run --report=aggregate| Path | What it covers |
|---|---|
test/unit/ |
Individual classes (image operations, LZW codec, format en/decoders) |
test/integration/ |
Round-trip reads of real image files (BMP Suite, PyGIF, pngsuite) |
test/benchmark/ |
PHPBench benchmarks for scale, convert and codec operations |
- See the
example/sub-folder for snippets. - Source: https://github.com/GBLIX/gfx-php
This project is open to all kinds of contributions, including suggestions, documentation fixes, examples, formats and image processing algorithms.
See the issue tracker. Code contributions must be releasable under LGPL-2.1-or-later.
As a small project, we can't do everything. In particular, gfx-php is not likely to ever perform non-raster operations:
- vector image formats (PDF, SVG, EPS, etc).
- anything involving vector fonts
This repository uses test files from other projects:
- Imagine, which wraps available libraries.