Skip to content

Commit 514d8fd

Browse files
committed
switch to camel case, where we can
things like `ifthenelse` are still all mashed up, though
1 parent d22b16c commit 514d8fd

23 files changed

+74
-55
lines changed

README.md

+34-15
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,58 @@ which gives some more background.
2222
<?php
2323
include 'vips.php';
2424

25-
$image = Vips\Image::new_from_file($argv[1]);
25+
$image = Vips\Image::newFromFile($argv[1]);
2626

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

2929
$image = $image->invert();
3030

31-
$image->write_to_file($argv[2]);
31+
$image->writeToFile($argv[2]);
3232
?>
3333
```
3434

35-
### TODO
35+
Almost all methods return a new image for the result, so you can chain them.
36+
For example:
3637

37-
Broken:
38+
```
39+
$image = $image->more(12)->ifThenElse(255, $image);
40+
```
3841

39-
* phpDoc is not working for some reason.
42+
will make a mask of pixels greater than 12, then use the mask to set pixels to
43+
either 255 or the original image.
4044

41-
Some features that other vips bindings have are not yet implemented:
45+
You use long, double, array and image as parameters. For example:
4246

43-
* Not tried to make a proper package or namespace it yet. Does not
44-
install `vips.php`.
47+
```
48+
$image = $image->add(2);
49+
```
4550

46-
* You can't assign to an array index to change an image band.
51+
to add two to every band element, or:
4752

48-
* In-place operations, like `circle`, are not yet supported.
53+
```
54+
$image = $image->add([1, 2, 3]);
55+
```
4956

50-
* No exceptions yet.
57+
to add 1 to the first band, 2 to the second and 3 to the third. Or:
5158

52-
* No logging at the moment.
59+
```
60+
$image = $image->add($image2);
61+
```
62+
63+
to add two images.
64+
65+
Almost all methods can take an optional final argument, an array of options.
66+
For example:
67+
68+
```
69+
$image->writeToFile("fred.jpg", ["Q" => 90]);
70+
$image = $image->embed("fred.jpg", ["Q" => 90]);
71+
```
5372

54-
Some things will never be done:
73+
There are around 300 operations in the library, see the vips docs for an
74+
introduction:
5575

56-
* You can't use `()` to get a pixel value, since php does not support multiple
57-
arguments to `__invoke()`.
76+
http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/
5877

5978
### How it works
6079

tests/018.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ can import Vips\Image class
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([1, 2, 3]);
9+
$image = Vips\Image::newFromArray([1, 2, 3]);
1010
?>
1111
--EXPECT--

tests/019.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
--TEST--
2-
Vips\Image::new_from_file works
2+
Vips\Image::newFromFile works
33
--SKIPIF--
44
<?php if (!extension_loaded("vips")) print "skip"; ?>
55
--FILE--
66
<?php
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename, ["shrink" => 2]);
10+
$image = Vips\Image::newFromFile($filename, ["shrink" => 2]);
1111
if ($image->width == 800) {
1212
echo "pass\n";
1313
}

tests/020.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Vips\Image::new_from_buffer works
2+
Vips\Image::newFromBuffer works
33
--SKIPIF--
44
<?php if (!extension_loaded("vips")) print "skip"; ?>
55
--FILE--
@@ -9,7 +9,7 @@ Vips\Image::new_from_buffer works
99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
1010
$buffer = file_get_contents($filename);
1111

12-
$image = Vips\Image::new_from_buffer($buffer, "", ["shrink" => 2]);
12+
$image = Vips\Image::newFromBuffer($buffer, "", ["shrink" => 2]);
1313
if ($image->width == 800) {
1414
echo "pass\n";
1515
}

tests/021.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
--TEST--
2-
Vips\Image::new_from_array works
2+
Vips\Image::newFromArray works
33
--SKIPIF--
44
<?php if (!extension_loaded("vips")) print "skip"; ?>
55
--FILE--
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([1, 2, 3], 8, 12);
9+
$image = Vips\Image::newFromArray([1, 2, 3], 8, 12);
1010

1111
if ($image->width == 3 &&
1212
$image->height == 1 &&

tests/022.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Vips\Image::write_to_file works
2+
Vips\Image::writeToFile works
33
--SKIPIF--
44
<?php if (!extension_loaded("vips")) print "skip"; ?>
55
--FILE--
@@ -9,9 +9,9 @@ Vips\Image::write_to_file works
99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
1010
$output_filename = dirname(__FILE__) . "/x.tif";
1111

12-
$image = Vips\Image::new_from_file($filename);
13-
$image->write_to_file($output_filename);
14-
$image = Vips\Image::new_from_file($output_filename);
12+
$image = Vips\Image::newFromFile($filename);
13+
$image->writeToFile($output_filename);
14+
$image = Vips\Image::newFromFile($output_filename);
1515

1616
if ($image->width == 1600) {
1717
echo "pass";

tests/023.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Vips\Image::write_to_buffer works
2+
Vips\Image::writeToBuffer works
33
--SKIPIF--
44
<?php if (!extension_loaded("vips")) print "skip"; ?>
55
--FILE--
@@ -9,11 +9,11 @@ Vips\Image::write_to_buffer works
99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
1010
$output_filename = dirname(__FILE__) . "/x.jpg";
1111

12-
$image = Vips\Image::new_from_file($filename);
12+
$image = Vips\Image::newFromFile($filename);
1313

14-
$buffer1 = $image->write_to_buffer(".jpg");
14+
$buffer1 = $image->writeToBuffer(".jpg");
1515

16-
$image->write_to_file($output_filename);
16+
$image->writeToFile($output_filename);
1717
$buffer2 = file_get_contents($output_filename);
1818

1919
if ($buffer1 == $buffer2) {

tests/024.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Vips\Image::__call works
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
1010

11-
$image = Vips\Image::new_from_file($filename);
11+
$image = Vips\Image::newFromFile($filename);
1212
$image = $image->embed(10, 20, 3000, 2000, ["extend" => "copy"]);
1313

1414
if ($image->width == 3000) {

tests/028.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vips\Image::bandjoin works
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([[1, 2, 3], [4, 5, 6]]);
9+
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
1010
$rgb = $image->bandjoin([$image, $image]);
1111

1212
if ($rgb->bands == 3 &&

tests/029.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vips\Image::add(const) works
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([[1, 2, 3], [4, 5, 6]]);
9+
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
1010
$image = $image->add(1);
1111

1212
$pixel = $image->crop(0, 0, 1, 1);

tests/030.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vips\Image::getpoint() works
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([[1, 2, 3], [4, 5, 6]]);
9+
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
1010
$rgb = $image->bandjoin([$image, $image]);
1111
$rgb = $rgb->add(1);
1212

tests/031.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vips\Image::bandjoin(const) works
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([[1, 2, 3], [4, 5, 6]]);
9+
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
1010
$imagea = $image->bandjoin(255);
1111

1212
$pixel = $imagea->getpoint(0, 0);

tests/032.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __set and __get work
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image->poop = "banana";
1313
$value = $image->poop;

tests/033.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::ifthenelse(image, const) works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image = $image->more(34)->ifthenelse(255, $image);
1313

tests/034.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::ifthenelse(const, image) works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image = $image->more(34)->ifthenelse($image, 255);
1313

tests/035.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::ifthenelse(const, const) works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image = $image->more(34)->ifthenelse(128, 255);
1313

tests/036.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ operator expansions all work
2121
}
2222

2323
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
24-
$image = Vips\Image::new_from_file($filename);
24+
$image = Vips\Image::newFromFile($filename);
2525

2626
$pass = TRUE;
2727

tests/037.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vips\Image::maxpos works
66
<?php
77
include 'vips.php';
88

9-
$image = Vips\Image::new_from_array([[1, 2, 3], [4, 5, 6]]);
9+
$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
1010

1111
$result = $image->maxpos();
1212

tests/038.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::bandrank() works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image = $image->bandrank($image);
1313

tests/039.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rounding works
2121
}
2222

2323
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
24-
$image = Vips\Image::new_from_file($filename);
24+
$image = Vips\Image::newFromFile($filename);
2525
$image = $image->add([0.1, 1.5, 0.9]);
2626

2727
$pass = TRUE;

tests/040.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::bandand works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$pass = TRUE;
1313

tests/041.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vips\Image::[] works
77
include 'vips.php';
88

99
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
10-
$image = Vips\Image::new_from_file($filename);
10+
$image = Vips\Image::newFromFile($filename);
1111

1212
$image = $image->invert()[1];
1313

vips.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Image implements \ArrayAccess
6363
* Wrap a Vips\Image around an underlying vips resource.
6464
*
6565
* Don't call this yourself, users should stick to (for example)
66-
* Vips\Image::new_from_file().
66+
* Vips\Image::newFromFile().
6767
*
6868
* @param resource $image The underlying vips image resource that this
6969
* class should wrap.
@@ -120,7 +120,7 @@ static private function is_2D($value)
120120
private static function imageize($match_image, $value)
121121
{
122122
if (self::is_2D($value)) {
123-
$result = self::new_from_array($value);
123+
$result = self::newFromArray($value);
124124
}
125125
else {
126126
$pixel = self::black(1, 1)->add($value)->cast($match_image->format);
@@ -192,7 +192,7 @@ private static function wrap($result)
192192
*
193193
* @return A new Vips\Image.
194194
*/
195-
public static function new_from_file($filename, $options = [])
195+
public static function newFromFile($filename, $options = [])
196196
{
197197
$options = self::unwrap($options);
198198
$result = vips_image_new_from_file($filename, $options);
@@ -209,7 +209,7 @@ public static function new_from_file($filename, $options = [])
209209
*
210210
* @return A new Vips\Image.
211211
*/
212-
public static function new_from_buffer($buffer,
212+
public static function newFromBuffer($buffer,
213213
$option_string = "", $options = [])
214214
{
215215
$options = self::unwrap($options);
@@ -230,7 +230,7 @@ public static function new_from_buffer($buffer,
230230
*
231231
* @return A new Vips\Image.
232232
*/
233-
public static function new_from_array($array, $scale = 1, $offset = 0)
233+
public static function newFromArray($array, $scale = 1, $offset = 0)
234234
{
235235
$result = vips_image_new_from_array($array, $scale, $offset);
236236
return self::wrap($result);
@@ -245,7 +245,7 @@ public static function new_from_array($array, $scale = 1, $offset = 0)
245245
*
246246
* @return bool TRUE for success and FALSE for failure.
247247
*/
248-
public function write_to_file($filename, $options = [])
248+
public function writeToFile($filename, $options = [])
249249
{
250250
$options = self::unwrap($options);
251251
$result = vips_image_write_to_file($this->image, $filename, $options);
@@ -261,7 +261,7 @@ public function write_to_file($filename, $options = [])
261261
*
262262
* @return string The formatted image.
263263
*/
264-
public function write_to_buffer($suffix, $options = [])
264+
public function writeToBuffer($suffix, $options = [])
265265
{
266266
$options = self::unwrap($options);
267267
$result = vips_image_write_to_buffer($this->image, $suffix, $options);
@@ -488,7 +488,7 @@ public function more($other, $options = [])
488488
return self::call_enum($other, "relational", "more", $options);
489489
}
490490

491-
public function moreeq($other, $options = [])
491+
public function moreEq($other, $options = [])
492492
{
493493
return self::call_enum($other, "relational", "moreeq", $options);
494494
}
@@ -498,7 +498,7 @@ public function less($other, $options = [])
498498
return self::call_enum($other, "relational", "less", $options);
499499
}
500500

501-
public function lesseq($other, $options = [])
501+
public function lessEq($other, $options = [])
502502
{
503503
return self::call_enum($other, "relational", "lesseq", $options);
504504
}
@@ -508,7 +508,7 @@ public function equal($other, $options = [])
508508
return self::call_enum($other, "relational", "equal", $options);
509509
}
510510

511-
public function noteq($other, $options = [])
511+
public function notEq($other, $options = [])
512512
{
513513
return self::call_enum($other, "relational", "noteq", $options);
514514
}

0 commit comments

Comments
 (0)