Skip to content

Commit ad44dfd

Browse files
committed
more tests
1 parent 54ecc31 commit ad44dfd

File tree

5 files changed

+143
-3
lines changed

5 files changed

+143
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ php > $im = new Imagick();
132132
```
133133

134134
we get an error from composer, even though `php -i` says that vips is enabled
135+
136+
* do `tests/old/036.phpt` next

tests/call.php

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
use Vips\Image\Image;
4+
5+
class VipsCallTest extends PHPUnit_Framework_TestCase
6+
{
7+
8+
public function testVipsCall()
9+
{
10+
$image = Image::newFromArray([1, 2, 3]);
11+
$image = $image->embed(10, 20, 3000, 2000, ["extend" => "copy"]);
12+
13+
$this->assertEquals($image->width, 3000);
14+
$this->assertEquals($image->height, 2000);
15+
$this->assertEquals($image->bands, 1);
16+
}
17+
18+
public function testVipsCallStatic()
19+
{
20+
$image = Image::black(1, 2, ["bands" => 3]);
21+
22+
$this->assertEquals($image->width, 1);
23+
$this->assertEquals($image->height, 2);
24+
$this->assertEquals($image->bands, 3);
25+
}
26+
27+
public function testVipsBandjoin()
28+
{
29+
$image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
30+
$rgb = $image->bandjoin([$image, $image]);
31+
32+
$this->assertEquals($rgb->width, 3);
33+
$this->assertEquals($rgb->height, 2);
34+
$this->assertEquals($rgb->bands, 3);
35+
}
36+
37+
public function testVipsAddConst()
38+
{
39+
$image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
40+
$image = $image->add(1);
41+
$pixel = $image->crop(0, 0, 1, 1)->avg();
42+
43+
$this->assertEquals($pixel, 2);
44+
}
45+
46+
public function testVipsGetPoint()
47+
{
48+
$image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
49+
$rgb = $image->bandjoin([$image, $image]);
50+
$rgb = $rgb->add(1);
51+
$pixel = $rgb->getpoint(0, 0);
52+
53+
$this->assertEquals($pixel, [2, 2, 2]);
54+
}
55+
56+
public function testVipsBandjoinConst()
57+
{
58+
$image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
59+
$imagea = $image->bandjoin(255);
60+
$pixel = $imagea->getpoint(0, 0);
61+
62+
$this->assertEquals($pixel, [1, 255]);
63+
}
64+
65+
public function testVipsIfthenelseConst()
66+
{
67+
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
68+
$image = Image::newFromFile($filename);
69+
70+
$if = $image->more(34)->ifthenelse(255, $image);
71+
$pixel = $if->getpoint(0, 0);
72+
$this->assertEquals($pixel, [255, 255, 34]);
73+
74+
$if = $image->more(34)->ifthenelse($image, 255);
75+
$pixel = $if->getpoint(0, 0);
76+
$this->assertEquals($pixel, [39, 38, 255]);
77+
78+
$if = $image->more(34)->ifthenelse(128, 255);
79+
$pixel = $if->getpoint(0, 0);
80+
$this->assertEquals($pixel, [128, 128, 255]);
81+
}
82+
83+
84+
}

tests/meta.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Vips\Image\Image;
4+
5+
class VipsMetaTest extends PHPUnit_Framework_TestCase
6+
{
7+
8+
public function testVipsSetGet()
9+
{
10+
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
11+
$image = Image::newFromFile($filename, ["shrink" => 2]);
12+
13+
$image->poop = "banana";
14+
$value = $image->poop;
15+
16+
$this->assertEquals($value, "banana");
17+
}
18+
19+
}

tests/new.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Vips\Image\Image;
44

5-
class VipsTest extends PHPUnit_Framework_TestCase
5+
class VipsNewTest extends PHPUnit_Framework_TestCase
66
{
77

88
public function testVipsNewFromArray()

tests/write.php

+37-2
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,55 @@
22

33
use Vips\Image\Image;
44

5-
class VipsTest extends PHPUnit_Framework_TestCase
5+
class VipsWriteTest extends PHPUnit_Framework_TestCase
66
{
77

8+
function setUp()
9+
{
10+
$this->tmps[] = array();
11+
}
12+
13+
function tearDown()
14+
{
15+
foreach ($this->tmps as $tmp) {
16+
@unlink($tmp);
17+
}
18+
}
19+
20+
function tmp($suffix)
21+
{
22+
$tmp = tempnam(sys_get_temp_dir(), 'vips-test');
23+
unlink($tmp);
24+
// race condition, sigh
25+
$tmp .= $suffix;
26+
$this->tmps[] = $tmp;
27+
return $tmp;
28+
}
29+
830
public function testVipsWriteToFile()
931
{
1032
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
1133
$image = Image::newFromFile($filename, ["shrink" => 2]);
34+
$output_filename = $this->tmp(".tif");
35+
$image->writeToFile($output_filename);
36+
$image = Image::newFromFile($output_filename);
1237

1338
$this->assertEquals($image->width, 800);
1439
$this->assertEquals($image->height, 600);
1540
$this->assertEquals($image->bands, 3);
41+
}
42+
43+
public function testVipsWriteToBuffer()
44+
{
45+
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
46+
$image = Image::newFromFile($filename, ["shrink" => 2]);
1647

17-
$output_filename = dirname(__FILE__) . "/x.tif";
48+
$buffer1 = $image->writeToBuffer(".jpg");
49+
$output_filename = $this->tmp(".jpg");
50+
$image->writeToFile($output_filename);
51+
$buffer2 = file_get_contents($output_filename);
1852

53+
$this->assertEquals($buffer1, $buffer2);
1954
}
2055

2156
}

0 commit comments

Comments
 (0)