-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathNewTest.php
114 lines (91 loc) · 3.51 KB
/
NewTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Jcupitt\Vips\Test;
use Jcupitt\Vips;
use PHPUnit\Framework\TestCase;
class NewTest extends TestCase
{
public function testVipsNewFromArray()
{
$image = Vips\Image::newFromArray([1, 2, 3]);
$this->assertEquals($image->width, 3);
$this->assertEquals($image->height, 1);
$this->assertEquals($image->bands, 1);
$image = Vips\Image::newFromArray([1, 2, 3], 8, 12);
$this->assertEquals($image->width, 3);
$this->assertEquals($image->height, 1);
$this->assertEquals($image->bands, 1);
$this->assertEquals($image->scale, 8);
$this->assertEquals($image->offset, 12);
}
public function testVipsNewFromFile()
{
$filename = __DIR__ . '/images/img_0076.jpg';
$image = Vips\Image::newFromFile($filename);
$this->assertEquals($image->width, 1600);
$this->assertEquals($image->height, 1200);
$this->assertEquals($image->bands, 3);
}
public function testVipsNewFromImage()
{
$filename = __DIR__ . '/images/img_0076.jpg';
$image = Vips\Image::newFromFile($filename);
$image2 = $image->newFromImage(12);
$this->assertEquals($image2->width, $image->width);
$this->assertEquals($image2->height, $image->height);
$this->assertEquals($image2->format, $image->format);
$this->assertEquals($image2->xres, $image->xres);
$this->assertEquals($image2->yres, $image->yres);
$this->assertEquals($image2->xoffset, $image->xoffset);
$this->assertEquals($image2->yoffset, $image->yoffset);
$this->assertEquals($image2->bands, 1);
$this->assertEquals($image2->avg(), 12);
$image2 = $image->newFromImage([1, 2, 3]);
$this->assertEquals($image2->bands, 3);
$this->assertEquals($image2->avg(), 2);
}
public function testVipsNewFromBuffer()
{
$filename = __DIR__ . '/images/img_0076.jpg';
$buffer = file_get_contents($filename);
$image = Vips\Image::newFromBuffer($buffer);
$this->assertEquals($image->width, 1600);
$this->assertEquals($image->height, 1200);
$this->assertEquals($image->bands, 3);
}
public function testVipsCopyMemory()
{
$filename = __DIR__ . '/images/img_0076.jpg';
$image1 = Vips\Image::newFromFile($filename);
$image2 = $image1->copyMemory();
$this->assertEquals($image1->avg(), $image2->avg());
}
public function testVipsNewInterpolator()
{
$filename = __DIR__ . '/images/img_0076.jpg';
$image1 = Vips\Image::newFromFile($filename);
$interp = Vips\Image::newInterpolator('bicubic');
$image2 = $image1->affine([2, 0, 0, 2], ['interpolate' => $interp]);
$widthInput = $image1->width;
$widthOutput = $image2->width;
$this->assertNotNull($interp);
$this->assertEquals($widthInput * 2, $widthOutput);
}
public function testVipsNewFromMemory()
{
$binaryStr = pack('C*', ...array_fill(0, 200, 0));
$image = Vips\Image::newFromMemory($binaryStr, 20, 10, 1, Vips\BandFormat::UCHAR);
$this->assertEquals($image->width, 20);
$this->assertEquals($image->height, 10);
$this->assertEquals($image->format, Vips\BandFormat::UCHAR);
$this->assertEquals($image->bands, 1);
$this->assertEquals($image->avg(), 0);
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: expandtab sw=4 ts=4 fdm=marker
* vim<600: expandtab sw=4 ts=4
*/