WP Manifestindependent plugin directory
manifest / media / imagination

Imagination

Adds libvips support to WordPress for faster and more memory-efficient image processing.

by Kirill S. · github.com/kirsky/imagination · website

★ 0stars
0forks

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.zip

Make 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.enable set to true for the PHP that runs WordPress. The default value preload is 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.
  • curl and sha256sum, which the Composer scripts use to fetch and check Strauss (see below).

Imagination is tested on Linux only.

Install from source

  1. Clone this repository into wp-content/plugins/imagination.

  2. Run this in the plugin folder:

    composer install --no-dev -o
  3. 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:

  1. Composer downloads bin/strauss.phar (version 0.30.0) and checks its SHA-256 sum.
  2. Strauss copies php-vips and PSR Log into vendor-prefixed/ and renames their namespaces.
  3. 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:

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.