Skip to content

Commit 3379730

Browse files
committed
first commit
broken off from php-vips
0 parents  commit 3379730

39 files changed

+2407
-0
lines changed

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.deps
2+
*.lo
3+
*.swp
4+
*.la
5+
.libs
6+
acinclude.m4
7+
aclocal.m4
8+
autom4te.cache
9+
build
10+
docs
11+
config.guess
12+
config.h
13+
config.h.in
14+
config.log
15+
config.nice
16+
config.status
17+
config.sub
18+
configure
19+
configure.in
20+
include
21+
install-sh
22+
libtool
23+
ltmain.sh
24+
Makefile
25+
Makefile.fragments
26+
Makefile.global
27+
Makefile.objects
28+
missing
29+
mkinstalldirs
30+
modules
31+
run-tests.php
32+
tests/*/*.diff
33+
tests/*/*.out
34+
tests/*/*.php
35+
tests/*/*.exp
36+
tests/*/*.log
37+
tests/*/*.sh

API-0.1.0

Whitespace-only changes.

CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
;; vips
2+
John Cupitt <[email protected]> lead

EXPERIMENTAL

Whitespace-only changes.

LICENSE.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2016 John Cupitt
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Low-level PHP binding for libvips
2+
3+
This extension lets you use the libvips image processing library from PHP. It is
4+
intentionally very low-level. Modules such as `vips` build a nice API on
5+
top of this extension.
6+
7+
libvips is fast and it can work without needing to have the
8+
entire image loaded into memory. Programs that use libvips don't
9+
manipulate images directly, instead they create pipelines of image processing
10+
operations building on a source image. When the end of the pipe is connected
11+
to a destination, the whole pipline executes at once, streaming the image
12+
in parallel from source to destination in a set of small fragments.
13+
14+
See the [benchmarks at the official libvips
15+
website](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use).
16+
There's a handy blog post explaining [how libvips opens
17+
files](http://libvips.blogspot.co.uk/2012/06/how-libvips-opens-file.html)
18+
which gives some more background.
19+
20+
### Example
21+
22+
```php
23+
#!/usr/bin/env php
24+
<?php
25+
if (!extension_loaded("vips")) {
26+
dl('vips.' . PHP_SHLIB_SUFFIX);
27+
}
28+
29+
$x = vips_image_new_from_file($argv[1])["out"];
30+
$x = vips_call("invert", $x)["out"];
31+
vips_image_write_to_file($x, $argv[2]);
32+
?>
33+
```
34+
35+
Almost all operations return an array of result values. Usually there is a
36+
single result called `"out"`.
37+
38+
Use `vips_call()` to call any operation in the vips library. There are around
39+
around 300 operations available, see the vips docs for an
40+
introduction:
41+
42+
http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/
43+
44+
Arguments can be long, double, image, array of long, array of double or array
45+
of image. The final argument to `vips_call()` is an array of operation options.
46+
47+
### Preparation
48+
49+
PHP is normally built for speed and is missing a lot of debugging support you
50+
need for extension development. For testing and dev, build your own php.
51+
I used 7.0.10 and configured with:
52+
53+
```
54+
$ ./configure --prefix=/home/john/vips --enable-debug --enable-maintainer-zts \
55+
--enable-cgi --enable-cli --with-readline --with-openssl
56+
```
57+
58+
You'll need libvips 8.0 or later, including all the headers for development.
59+
On linux, install with your package manager.
60+
On OS X, install with `brew` or MacPorts. For Windows, download a zip from
61+
the libvips
62+
website, or build your own.
63+
64+
### Regenerate build system
65+
66+
Run:
67+
68+
```
69+
$ phpize
70+
```
71+
72+
To scan `config.m4` and your php install and regenerate the build system.
73+
74+
### Configuring
75+
76+
Run
77+
78+
```
79+
$ ./configure
80+
```
81+
82+
Check the output carefully for errors, and obviously check that it found your
83+
libvips.
84+
85+
### Installing
86+
87+
Run:
88+
89+
90+
```
91+
$ make
92+
```
93+
94+
To build the module to the `modules/` directory in this repository.
95+
96+
Don't post php-vips test results to php.net! Stop this with:
97+
98+
99+
```
100+
$ export NO_INTERACTION=1
101+
```
102+
103+
104+
Test with:
105+
106+
107+
```
108+
$ make test
109+
```
110+
111+
Finally, install to your php extensions area with:
112+
113+
```
114+
$ make install
115+
```
116+
117+
### Using
118+
119+
Try:
120+
121+
```php
122+
#!/usr/bin/env php
123+
<?php
124+
if (!extension_loaded("vips")) {
125+
dl('vips.' . PHP_SHLIB_SUFFIX);
126+
}
127+
128+
$x = vips_image_new_from_file($argv[1])["out"];
129+
vips_image_write_to_file($x, $argv[2]);
130+
?>
131+
```
132+
133+
And run with:
134+
135+
```
136+
$ ./try1.php ~/pics/k2.jpg x.tif
137+
```
138+
139+
See `examples/`.
140+
141+
### Links
142+
143+
http://php.net/manual/en/internals2.php
144+
145+
https://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
146+
147+
https://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/
148+
149+
https://devzone.zend.com/446/extension-writing-part-iii-resources/
150+
151+
### Documentation
152+
153+
```
154+
$ pear channel-discover pear.phpdoc.org
155+
$ pear install phpdoc/phpDocumentor
156+
$ phpdoc
157+
```
158+

RELEASE-0.1.0

Whitespace-only changes.

config.m4

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
dnl $Id$
2+
dnl config.m4 for extension vips
3+
4+
PHP_ARG_WITH(vips, for vips support,
5+
[ --with-vips Include vips support])
6+
7+
VIPS_MIN_VERSION=8.3
8+
9+
if test x"$PHP_VIPS" != x"no"; then
10+
if ! pkg-config --atleast-pkgconfig-version 0.2; then
11+
AC_MSG_ERROR([you need at least pkg-config 0.2 for this module])
12+
PHP_VIPS=no
13+
fi
14+
fi
15+
16+
if test x"$PHP_VIPS" != x"no"; then
17+
if ! pkg-config vips --atleast-version $VIPS_MIN_VERSION; then
18+
AC_MSG_ERROR([you need at least vips $VIPS_MIN_VERSION for this module])
19+
PHP_VIPS=no
20+
fi
21+
fi
22+
23+
if test x"$PHP_VIPS" != x"no"; then
24+
VIPS_CFLAGS=`pkg-config vips --cflags-only-other`
25+
VIPS_INCS=`pkg-config vips --cflags-only-I`
26+
VIPS_LIBS=`pkg-config vips --libs`
27+
28+
PHP_CHECK_LIBRARY(vips, vips_init,
29+
[
30+
PHP_EVAL_INCLINE($VIPS_INCS)
31+
PHP_EVAL_LIBLINE($VIPS_LIBS, VIPS_SHARED_LIBADD)
32+
],[
33+
AC_MSG_ERROR([libvips not found. Check config.log for more information.])
34+
],[$VIPS_LIBS]
35+
)
36+
37+
AC_DEFINE(HAVE_VIPS, 1, [Whether you have vips])
38+
PHP_NEW_EXTENSION(vips, vips.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $VIPS_CFLAGS)
39+
PHP_SUBST(VIPS_SHARED_LIBADD)
40+
fi
41+

config.w32

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
ARG_WITH("vips", "for vips support", "no");
5+
6+
if (PHP_VIPS != "no") {
7+
EXTENSION("vips", "vips.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
8+
}
9+

examples/vips_array.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$array = vips_image_new_from_array([1, 2, 3]);
6+
7+
vips_image_write_to_file($array ,$argv[1]);
8+
?>

examples/vips_call.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$x = vips_image_new_from_file($argv[1])["out"];
6+
7+
$result = vips_call("invert", $x);
8+
$x = $result["out"];
9+
10+
vips_image_write_to_file($x, $argv[2]);
11+
?>

examples/vips_copy.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$x = vips_image_new_from_file($argv[1])["out"];
6+
vips_image_write_to_file($x, $argv[2]);
7+
?>

examples/vips_icc_profile.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$x = vips_image_new_from_file($argv[1])["out"];
6+
$type = vips_image_get_typeof($x, "icc-profile-data");
7+
8+
if ($type > 0) {
9+
$profile = vips_image_get($x, "icc-profile-data");
10+
echo $argv[1], " profile, ", strlen($profile), " bytes of data\n";
11+
}
12+
else {
13+
echo $argv[1], " has no profile\n";
14+
}
15+
?>

examples/vips_linear.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$image = vips_image_new_from_array([[1, 2, 3], [4, 5, 6]]);
6+
$rgb = vips_call("bandjoin", NULL, [$image, $image, $image])["out"];
7+
8+
# multiply R by 2
9+
$rgb = vips_call("linear", $rgb, [2, 1, 1], [0, 0, 0])["out"];
10+
11+
vips_image_write_to_file($rgb, "x.v");
12+
?>

examples/vips_linear1.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$image = vips_image_new_from_array([[1, 2, 3], [4, 5, 6]]);
6+
$rgb = vips_call("bandjoin", NULL, [$image, $image, $image])["out"];
7+
8+
# multiply R by 2
9+
$rgb = vips_call("linear", $rgb, 2, 0)["out"];
10+
11+
vips_image_write_to_file($rgb, "x.v");
12+
?>

examples/vips_min.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env php
2+
<?php
3+
dl('vips.' . PHP_SHLIB_SUFFIX);
4+
5+
$point = vips_call("black", NULL, 1, 1)["out"];
6+
$image = vips_call("embed", $point, 10, 20, 100, 100,
7+
array("extend" => "white"))["out"];
8+
9+
$result = vips_call("min", $image,
10+
array("x" => true, "y" => true, "x_array" => true));
11+
echo "out = ";
12+
var_dump($result);
13+
$mn = $result["out"];
14+
$x = $result["x"];
15+
$y = $result["y"];
16+
$x_array = $result["x_array"];
17+
18+
echo "min = ", $mn, "\n";
19+
echo "x = ", $x, "\n";
20+
echo "y = ", $y, "\n";
21+
echo "x_array = [";
22+
for ($i = 0; $i < count($x_array); $i++) {
23+
if ($i > 0) {
24+
echo ", ";
25+
}
26+
echo $x_array[$i];
27+
}
28+
echo "]\n";
29+
?>

0 commit comments

Comments
 (0)