Thursday, 24 November 2016

php-vips hits 1.0

It's been a couple of months since the announcement, but php-vips has now reached 1.0 and made it into PECL! All the TODO items have been ticked off, and it's now relatively easy to install and try out.

php-vips is rather like imagick, but, at least on this benchmark, 4x faster and needs 10x less memory.

To install, see the README, but briefly:
  1. Install the development version of the underlying libvips library. It's in the linux package managers, homebrew and MacPorts, and there are Windows binaries on the vips website. For example, on Debian:
    sudo apt-get install libvips-dev
    Or macOS:
    brew install vips
  2. Install the binary PHP extension:
    pecl install vips
    You may need to add extension=vips.so or equivalent to php.ini, see the output of pecl.

  3. Add vips to your composer.json:
     "require": {
       "jcupitt/vips" : "1.0.0"
     }
    
Here's a simple example you can run from the command-line:
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

$image = Vips\Image::newFromFile($argv[1]);

echo "width = ", $image->width, "\n";

$image = $image->invert();

$image->writeToFile($argv[2]);
Run with:
$ composer install
$ ./try1.php ~/pics/k2.jpg x.tif
To load an image, invert it, and save again.

We have the full formatted docs on line as well, including a tutorial and some background on how the thing works. The examples/ directory has some more sample code.

No comments:

Post a Comment