|
1 | 1 | # Low-level PHP binding for libvips
|
2 | 2 |
|
3 |
| -This extension lets you use the libvips image processing library from PHP. It is |
4 |
| -intentionally very low-level. Modules such as |
5 |
| -https://github.com/jcupitt/php-vips try to layer a nice API on |
6 |
| -top of this. |
7 |
| - |
8 |
| -libvips is fast and it can work without needing to have the |
9 |
| -entire image loaded into memory. Programs that use libvips don't |
10 |
| -manipulate images directly, instead they create pipelines of image processing |
11 |
| -operations starting from a source image. When the end of the pipe is connected |
12 |
| -to a destination, the whole pipeline executes at once, streaming the image |
13 |
| -in parallel from source to destination in a set of small fragments. |
14 |
| - |
15 |
| -See the [benchmarks at the official libvips |
16 |
| -website](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use). |
17 |
| -There's a handy blog post explaining [how libvips opens |
18 |
| -files](http://libvips.blogspot.co.uk/2012/06/how-libvips-opens-file.html) |
19 |
| -which gives some more background. |
| 3 | +This extension lets you use the libvips image processing library from PHP 7. It |
| 4 | +is intentionally very low-level: modules such as |
| 5 | +https://github.com/jcupitt/php-vips try to layer a nice API on top of this. |
| 6 | + |
| 7 | +libvips is fast and needs little memory. The [`vips-php-bench`]( |
| 8 | +https://github.com/jcupitt/php-vips-bench) repository tests |
| 9 | +`php-vips` against `imagick` and `gd`: on that test, and on my laptop, |
| 10 | +`php-vips` is around four times faster than `imagick` and needs 10 times less |
| 11 | +memory. |
20 | 12 |
|
21 | 13 | ### Example
|
22 | 14 |
|
23 | 15 | ```php
|
24 | 16 | #!/usr/bin/env php
|
25 | 17 | <?php
|
26 |
| -if (!extension_loaded("vips")) { |
27 |
| - dl('vips.' . PHP_SHLIB_SUFFIX); |
28 |
| -} |
29 | 18 |
|
30 | 19 | $x = vips_image_new_from_file($argv[1])["out"];
|
31 | 20 | $x = vips_call("invert", $x)["out"];
|
32 | 21 | vips_image_write_to_file($x, $argv[2]);
|
33 |
| -?> |
34 | 22 | ```
|
35 | 23 |
|
36 | 24 | Almost all operations return an array of result values. Usually there is a
|
37 | 25 | single result called `"out"`.
|
38 | 26 |
|
39 | 27 | Use `vips_call()` to call any operation in the vips library. There are around
|
40 |
| -around 300 operations available, see the vips docs for an |
41 |
| -introduction: |
| 28 | +around 300 operations available, see the vips docs for an introduction: |
42 | 29 |
|
43 | 30 | http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/
|
44 | 31 |
|
45 | 32 | Arguments can be long, double, image, array of long, array of double or array
|
46 | 33 | of image. The final argument to `vips_call()` is an array of operation options.
|
47 | 34 |
|
48 |
| -### Preparation |
| 35 | +`php-vips` layers a nice API, including full docs, on top of this extension, |
| 36 | +see: |
49 | 37 |
|
50 |
| -PHP is normally built for speed and is missing a lot of debugging support you |
51 |
| -need for extension development. For testing and dev, build your own php. |
52 |
| -I used 7.0.11 and configured with: |
| 38 | +https://github.com/jcupitt/php-vips |
53 | 39 |
|
54 |
| -``` |
55 |
| -$ ./configure --prefix=/home/john/vips --enable-debug --enable-maintainer-zts \ |
56 |
| - --enable-cgi --enable-cli --with-readline --with-openssl --with-zlib \ |
57 |
| - --with-gd --with-jpeg-dir=/usr --with-libxml-dir=/usr |
58 |
| -``` |
| 40 | +### Installing |
59 | 41 |
|
60 |
| -You'll need libvips 8.0 or later, including all the headers for |
61 |
| -development. On linux, install with your package manager. On OS X, |
62 |
| -install with `brew` or MacPorts. For Windows, download a zip from the |
63 |
| -libvips website, or build your own. |
| 42 | +On OS X, use `brew install php70-vips` to install the libvips library, php and |
| 43 | +this php extension. |
64 | 44 |
|
65 |
| -### Installing |
| 45 | +On Linux, install this extension with: |
66 | 46 |
|
67 | 47 | ```
|
68 |
| -$ pear install vips-0.1.2.tgz |
| 48 | +$ pear install vips-0.1.3.tgz |
69 | 49 | ```
|
70 | 50 |
|
71 |
| -to install. |
72 |
| - |
73 |
| -Add: |
| 51 | +And add: |
74 | 52 |
|
75 | 53 | ```
|
76 | 54 | extension=vips.so
|
77 | 55 | ```
|
78 | 56 |
|
79 |
| -to your `php.ini`, perhaps in `~/vips/lib/php.ini`, if you configured php as |
80 |
| -above. |
81 |
| - |
82 |
| -### Using |
| 57 | +to your `php.ini`. |
83 | 58 |
|
84 |
| -Try: |
| 59 | +### Development: preparation |
85 | 60 |
|
86 |
| -```php |
87 |
| -#!/usr/bin/env php |
88 |
| -<?php |
89 |
| -if (!extension_loaded("vips")) { |
90 |
| - dl('vips.' . PHP_SHLIB_SUFFIX); |
91 |
| -} |
92 |
| - |
93 |
| -$x = vips_image_new_from_file($argv[1])["out"]; |
94 |
| -$x = vips_call("invert", $x)["out"]; |
95 |
| -vips_image_write_to_file($x, $argv[2]); |
96 |
| -?> |
97 |
| -``` |
98 |
| - |
99 |
| -And run with: |
| 61 | +PHP is normally built for speed and is missing a lot of debugging support you |
| 62 | +need for extension development. For testing and dev, build your own php. |
| 63 | +I used 7.0.11 and configured with: |
100 | 64 |
|
101 | 65 | ```
|
102 |
| -$ ./try1.php ~/pics/k2.jpg x.tif |
| 66 | +$ ./configure --prefix=/home/john/vips --enable-debug --enable-maintainer-zts \ |
| 67 | + --enable-cgi --enable-cli --with-readline --with-openssl --with-zlib \ |
| 68 | + --with-gd --with-jpeg-dir=/usr --with-libxml-dir=/usr |
103 | 69 | ```
|
104 | 70 |
|
105 |
| -See `examples/`. |
| 71 | +You'll need libvips 8.0 or later, including all the headers for |
| 72 | +development. On linux, install with your package manager. On OS X, |
| 73 | +install with `brew` or MacPorts. For Windows, download a zip from the |
| 74 | +libvips website, or build your own. |
106 | 75 |
|
107 | 76 | ### Development: regenerate build system
|
108 | 77 |
|
109 | 78 | ```
|
110 | 79 | $ pear package
|
111 | 80 | ```
|
112 | 81 |
|
113 |
| -to make `vips-0.1.2.tgz`. |
| 82 | +to make `vips-0.1.3.tgz`. |
114 | 83 |
|
115 | 84 | To install by hand:
|
116 | 85 |
|
@@ -159,6 +128,9 @@ Finally, install to your php extensions area with:
|
159 | 128 | $ make install
|
160 | 129 | ```
|
161 | 130 |
|
| 131 | +Add `extension-vips.so` to `php.ini`, perhaps in `~/vips/lib/php.ini`, |
| 132 | +if you configured php as above. |
| 133 | + |
162 | 134 | ### Links
|
163 | 135 |
|
164 | 136 | http://php.net/manual/en/internals2.php
|
|
0 commit comments