gblix / gfx-php
The pure PHP graphics library
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^11
README
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.
Features
- 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.
v1.0.0 changelog
- 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
Quick start
Requirements
- PHP 8.2 or newer
zlibextension, for reading PNG files
Installation
Install gblix/gfx-php with Composer:
composer require gblix/gfx-php
Basic usage
<?php use Mike42\GfxPhp\Image; $img = Image::fromFile('colorwheel256.png'); $img->write('test.gif');
Testing
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-test
Run only the unit tests:
docker run --rm gfx-php-test php vendor/bin/phpunit --testsuite unit
Run only the integration tests (reads real image files from test/resources/):
docker run --rm gfx-php-test php vendor/bin/phpunit --testsuite integration
Run benchmarks (PHPBench, scale/convert/codec operations):
docker run --rm gfx-php-test php vendor/bin/phpbench run --report=aggregate
Test layout
| 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 |
Further reading
- See the
example/sub-folder for snippets. - Source: https://github.com/GBLIX/gfx-php
Contributing
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.
Scope
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
Acknowledgements
This repository uses test files from other projects:
Similar projects
- Imagine, which wraps available libraries.