All Projects → libvips → Php Vips

libvips / Php Vips

Licence: mit
php binding for libvips

Projects that are alternatives of or similar to Php Vips

PHP-CPP-documentation
The documentation in chinese of PHP-CPP.
Stars: ✭ 35 (-88.18%)
Mutual labels:  php-extension
php aho corasick
Aho-Corasick string search algorithm PHP extension implementation.
Stars: ✭ 45 (-84.8%)
Mutual labels:  php-extension
ext-chunkutils2
PHP extension in C++ implementing the modern Minecraft: Bedrock subchunk format for PocketMine-MP 4.0
Stars: ✭ 26 (-91.22%)
Mutual labels:  php-extension
RapidPM
High performance extension that implements parts of PocketMine-MP (PMMP) with Zephir
Stars: ✭ 31 (-89.53%)
Mutual labels:  php-extension
phphll
HyperLogLog for PHP implemented as a C extension
Stars: ✭ 19 (-93.58%)
Mutual labels:  php-extension
ruby-vips-lambda
AWS Lambda Layer for Ruby Libvips Gem
Stars: ✭ 34 (-88.51%)
Mutual labels:  libvips
tast-process
An extension providing multi process for PHP 7
Stars: ✭ 27 (-90.88%)
Mutual labels:  php-extension
Zephir
Zephir is a compiled high level language aimed to the creation of C-extensions for PHP.
Stars: ✭ 3,086 (+942.57%)
Mutual labels:  php-extension
image-processing-pipeline
An image build orchestrator for the modern web
Stars: ✭ 43 (-85.47%)
Mutual labels:  libvips
libvips-lambda
libvips Executable for AWS Lambda
Stars: ✭ 43 (-85.47%)
Mutual labels:  libvips
php-rar
PECL rar extension
Stars: ✭ 35 (-88.18%)
Mutual labels:  php-extension
imagor
Fast, Docker-ready image processing server in Go and libvips
Stars: ✭ 2,276 (+668.92%)
Mutual labels:  libvips
panda
A simple extension for PHP
Stars: ✭ 45 (-84.8%)
Mutual labels:  php-extension
secp256k1-php
PHP bindings for bitcoin-core/secp256k1
Stars: ✭ 55 (-81.42%)
Mutual labels:  php-extension
raylib-php
PHP 8 Bindings to raylib
Stars: ✭ 112 (-62.16%)
Mutual labels:  php-extension
imgwizard
Simple server for On-the-Fly image processing in Go
Stars: ✭ 51 (-82.77%)
Mutual labels:  libvips
relay
The next-generation caching layer for PHP.
Stars: ✭ 21 (-92.91%)
Mutual labels:  php-extension
Skyapm Php Sdk
The PHP instrument agent for Apache SkyWalking
Stars: ✭ 292 (-1.35%)
Mutual labels:  php-extension
Study
手把手教你写PHP协程扩展(teach you to write php coroutine extension by hand)
Stars: ✭ 285 (-3.72%)
Mutual labels:  php-extension
wrender
Image compression and transformation reverse-proxy for Express apps
Stars: ✭ 14 (-95.27%)
Mutual labels:  libvips

PHP binding for libvips

Build Status

php-vips is a binding for libvips for PHP 7.

libvips is fast and needs little memory. The vips-php-bench repository tests php-vips against imagick and gd. On that test, and on my laptop, php-vips is around four times faster than imagick and needs 10 times less memory.

Programs that use libvips don't manipulate images directly, instead they create pipelines of image processing operations starting from a source image. When the pipe is connected to a destination, the whole pipeline executes at once and in parallel, streaming the image from source to destination in a set of small fragments.

This module builds upon the vips PHP extension:

https://github.com/libvips/php-vips-ext

You'll need to install that first. It's tested on Linux and macOS --- Windows would need some work, but should be possible.

See the README there, but briefly:

  1. Install the libvips library and headers. 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. You'll need a PHP development environment for this, since it will download and build the sources for the extension. For example, on Debian:

    sudo apt-get install php-pear
    

    Then to download and build the extension it's:

    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.7"
      }
    

Example

#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

// fast thumbnail generator
$image = Vips\Image::thumbnail('somefile.jpg', 128);
$image->writeToFile('tiny.jpg');

// load an image, get fields, process, save
$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

See examples/. We have a complete set of formatted API docs.

Introduction to the API

Almost all methods return a new image as the result, so you can chain them. For example:

$new_image = $image->more(12)->ifthenelse(255, $image);

will make a mask of pixels greater than 12, then use the mask to set pixels to either 255 or the original image.

Note that libvips operators always make new images, they don't modify existing images, so after the line above, $image is unchanged.

You use long, double, array and image as parameters. For example:

$image = $image->add(2);

to add two to every band element, or:

$image = $image->add([1, 2, 3]);

to add 1 to the first band, 2 to the second and 3 to the third. Or:

$image = $image->add($image2);

to add two images. Or:

$image = $image->add([[1, 2, 3], [4, 5, 6]]);

To make a 2 x 3 image from the array, then add that image to the original.

Almost all methods can take an extra final argument: an array of options. For example:

$image->writeToFile("fred.jpg", ["Q" => 90]);

php-vips comes with full API docs. To regenerate these from your sources, type:

$ vendor/bin/phpdoc

And look in docs/.

There are around 300 operations in the library, see the vips docs for an introduction:

https://libvips.github.io/libvips/API/current

How it works

The vips extension defines a simple but ugly way to call any libvips operation from PHP. It uses libvips' own introspection facilities and does not depend on anything else (so no gobject-introspection, for example). It's a fairly short 1,600 lines of C.

This module is a PHP layer over the ugly vips extension that tries to make a nice interface for programmers. It uses __call() and __get() to make all libvips operations appear as methods, and all libvips properties as properties of the PHP Vips\Image class.

Test and install

$ composer install
$ composer test
$ vendor/bin/phpdoc

Regenerate auto docs

$ cd src
$ ../examples/generate_phpdoc.py
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].