Skip to content

Commit b0408ba

Browse files
committed
vips_image_get() has an error return
now returns -1 for error, or ["out" => value] for success
1 parent 9ec30f5 commit b0408ba

File tree

9 files changed

+78
-85
lines changed

9 files changed

+78
-85
lines changed

ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ vips extension changelog
33
Version 0.1.1 (2016-10-03)
44
--------------------------
55
* Support draw operations
6-
* Add vips_error_buffer()
6+
* Add vips_error_buffer(), remove docref messages
7+
* return 0/-1 everywhere for error
8+
* vips_image_get() returns ["out" => value] | -1
79

810
Version 0.1.0 (2016-09-20)
911
--------------------------

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ libvips.
135135

136136
Run:
137137

138-
139138
```
140139
$ make
141140
```
@@ -144,15 +143,12 @@ To build the module to the `modules/` directory in this repository.
144143

145144
Don't post php-vips test results to php.net! Stop this with:
146145

147-
148146
```
149147
$ export NO_INTERACTION=1
150148
```
151149

152-
153150
Test with:
154151

155-
156152
```
157153
$ make test
158154
```

tests/004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ vips can get image header fields
66
<?php
77
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
88
$image = vips_image_new_from_file($filename)["out"];
9-
$width = vips_image_get($image, "width");
9+
$width = vips_image_get($image, "width")["out"];
1010
if ($width == 1600) {
1111
echo("pass\n");
1212
}

tests/007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ new_from_file supports optional args
66
<?php
77
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
88
$image = vips_image_new_from_file($filename, ["shrink" => 8])["out"];
9-
$width = vips_image_get($image, "width");
9+
$width = vips_image_get($image, "width")["out"];
1010
if ($width == 200) {
1111
echo "pass";
1212
}

tests/012.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ new_from_buffer works
88
$buffer = file_get_contents($filename);
99

1010
$image = vips_image_new_from_buffer($buffer)["out"];
11-
$width1 = vips_image_get($image, "width");
11+
$width1 = vips_image_get($image, "width")["out"];
1212

1313
$image = vips_image_new_from_buffer($buffer, "shrink=2")["out"];
14-
$width2 = vips_image_get($image, "width");
14+
$width2 = vips_image_get($image, "width")["out"];
1515

1616
$image = vips_image_new_from_buffer($buffer, "", ["shrink" => 4])["out"];
17-
$width3 = vips_image_get($image, "width");
17+
$width3 = vips_image_get($image, "width")["out"];
1818

1919
if ($width1 == 1600 &&
2020
$width2 = 800 &&

tests/014.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ new_from_array works
55
--FILE--
66
<?php
77
$image = vips_image_new_from_array([1, 2, 3]);
8-
$width1 = vips_image_get($image, "width");
9-
$height1 = vips_image_get($image, "height");
8+
$width1 = vips_image_get($image, "width")["out"];
9+
$height1 = vips_image_get($image, "height")["out"];
1010

1111
$image = vips_image_new_from_array([[1, 2, 3], [4, 5, 6]]);
12-
$width2 = vips_image_get($image, "width");
13-
$height2 = vips_image_get($image, "height");
12+
$width2 = vips_image_get($image, "width")["out"];
13+
$height2 = vips_image_get($image, "height")["out"];
1414

1515
if ($width1 == 3 &&
1616
$height1 == 1 &&

tests/016.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ new_from_array has optional scale and offset
55
--FILE--
66
<?php
77
$image = vips_image_new_from_array([1, 2, 3]);
8-
$scale1 = vips_image_get($image, "scale");
9-
$offset1 = vips_image_get($image, "offset");
8+
$scale1 = vips_image_get($image, "scale")["out"];
9+
$offset1 = vips_image_get($image, "offset")["out"];
1010

1111
$image = vips_image_new_from_array([1, 2, 3], 8);
12-
$scale2 = vips_image_get($image, "scale");
13-
$offset2 = vips_image_get($image, "offset");
12+
$scale2 = vips_image_get($image, "scale")["out"];
13+
$offset2 = vips_image_get($image, "offset")["out"];
1414

1515
$image = vips_image_new_from_array([1, 2, 3], 8, 12);
16-
$scale3 = vips_image_get($image, "scale");
17-
$offset3 = vips_image_get($image, "offset");
16+
$scale3 = vips_image_get($image, "scale")["out"];
17+
$offset3 = vips_image_get($image, "offset")["out"];
1818

1919
if ($scale1 == 1 &&
2020
$offset1 == 0 &&

tests/029.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
can get error messages
3+
--SKIPIF--
4+
<?php if (!extension_loaded("vips")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
8+
$image = vips_image_new_from_file($filename)["out"];
9+
10+
$rg = vips_call("extract_band", $image, 0, ["n" => 2])["out"];
11+
12+
# this should error out since it's 2 band image + 3 band image
13+
$err = vips_call("add", $image, $rg);
14+
$msg = vips_error_buffer();
15+
16+
if ($err == -1 &&
17+
$msg == "add: not one band or 3 bands\n") {
18+
echo "pass";
19+
}
20+
?>
21+
--EXPECT--
22+
pass

0 commit comments

Comments
 (0)