Imagination
Adds libvips support to WordPress for faster and more memory-efficient image processing.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/kirsky/imagination/archive/refs/heads/main.zipMake WordPress image processing very fast with libvips. It resizes and converts WebP, AVIF, HEIC and more. All local, no external services involved.
This page is for people who work with the source code. The description, the FAQ and the changelog for site owners are in readme.txt.
Requirements
- PHP 7.4 or newer (install guide).
- The PHP FFI extension, with
ffi.enableset totruefor the PHP that runs WordPress. The default valuepreloadis not enough. - libvips 8.12 or newer, installed as a system library (install guide). PHP-FPM must be able to load it, not only the command line PHP.
- Composer to install the PHP libraries.
curlandsha256sum, which the Composer scripts use to fetch and check Strauss (see below).
Imagination is tested on Linux only.
Install from source
-
Clone this repository into
wp-content/plugins/imagination. -
Run this in the plugin folder:
composer install --no-dev -o -
Activate Imagination in WordPress.
The plugin needs the vendor/ folder that Composer creates. Without it, wp-admin shows an error notice and the plugin does nothing.
The bundled libraries
Imagination uses php-vips to call libvips from PHP. It also uses PSR Log, which php-vips needs. Both are MIT licensed.
Other plugins can ship their own copy of php-vips. To avoid clashes, this plugin renames the namespaces of both libraries with Strauss. The result is committed in vendor-prefixed/. The code there is third party code with a new namespace prefix (Indigit\Imagination\Vendor\). It is not edited by hand.
composer install and composer update run Strauss for you:
- Composer downloads
bin/strauss.phar(version 0.30.0) and checks its SHA-256 sum. - Strauss copies php-vips and PSR Log into
vendor-prefixed/and renames their namespaces. - Composer rebuilds the autoloader.
On a clean checkout this leaves vendor-prefixed/ exactly as it is committed. git status shows no change.
composer/installers is also required. It installs Composer packages of type wordpress-plugin, like this one, into wp-content/plugins.
Development
Install the development tools as well:
composer install
Then use these commands:
| Command | What it does |
|---|---|
composer lint:php |
Checks the code style with PHP_CodeSniffer |
composer lint:php:fix |
Fixes what it can fix automatically |
composer phpstan |
Runs PHPStan at level 6 |
The tools and rule sets, all installed by Composer:
- WordPress Coding Standards, including its
WordPress-Extrarules. Indentation is tabs. - Slevomat Coding Standard.
- phpstan-wordpress, the WordPress extension for PHPStan.
- PHP_CodeSniffer Standards Composer Installer Plugin, which registers the rule sets with PHP_CodeSniffer.
The settings are in phpcs.xml and phpstan.neon. Neither tool checks vendor/ or vendor-prefixed/.
License
Imagination is free software under the GPL-2.0-or-later. The full text is in LICENSE.