1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
This file is part of WideImage. |
4
|
|
|
|
5
|
|
|
WideImage is free software; you can redistribute it and/or modify |
6
|
|
|
it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
the Free Software Foundation; either version 2.1 of the License, or |
8
|
|
|
(at your option) any later version. |
9
|
|
|
|
10
|
|
|
WideImage is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
GNU Lesser General Public License for more details. |
14
|
|
|
|
15
|
|
|
You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
along with WideImage; if not, write to the Free Software |
17
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18
|
|
|
|
19
|
|
|
* @package Tests |
20
|
|
|
**/ |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
namespace Test\WideImage; |
24
|
|
|
|
25
|
|
|
include_once __DIR__ . '/Operation/CustomOp.php'; |
26
|
|
|
|
27
|
|
|
use WideImage\WideImage; |
28
|
|
|
use WideImage\Canvas; |
29
|
|
|
use WideImage\Image; |
30
|
|
|
use WideImage\TrueColorImage; |
31
|
|
|
use WideImage\PaletteImage; |
32
|
|
|
use WideImage\Operation\CustomOp; |
33
|
|
|
use Test\WideImage_TestCase; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @package Tests |
37
|
|
|
*/ |
38
|
|
|
class ImageForOutput extends TrueColorImage |
39
|
|
|
{ |
40
|
|
|
public $headers = array(); |
41
|
|
|
|
42
|
|
|
public function writeHeader($name, $data) |
43
|
|
|
{ |
44
|
|
|
$this->headers[$name] = $data; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @package Tests |
50
|
|
|
*/ |
51
|
|
|
class TestableImage extends TrueColorImage |
52
|
|
|
{ |
53
|
|
|
public $headers = array(); |
54
|
|
|
|
55
|
|
|
public function __destruct() {} |
56
|
|
|
|
57
|
|
|
public function writeHeader($name, $data) |
58
|
|
|
{ |
59
|
|
|
$this->headers[$name] = $data; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @package Tests |
65
|
|
|
*/ |
66
|
|
|
class ImageTest extends WideImage_TestCase |
67
|
|
|
{ |
68
|
|
|
public function testFactories() |
69
|
|
|
{ |
70
|
|
|
$this->assertTrue(WideImage::createTrueColorImage(100, 100) instanceof TrueColorImage); |
71
|
|
|
$this->assertTrue(WideImage::createPaletteImage(100, 100) instanceof PaletteImage); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testDestructorUponUnset() |
75
|
|
|
{ |
76
|
|
|
$img = TrueColorImage::create(10, 10); |
77
|
|
|
$handle = $img->getHandle(); |
78
|
|
|
|
79
|
|
|
$this->assertTrue(WideImage::isValidImageHandle($handle)); |
80
|
|
|
|
81
|
|
|
unset($img); |
82
|
|
|
|
83
|
|
|
$this->assertFalse(WideImage::isValidImageHandle($handle)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testDestructorUponNull() |
87
|
|
|
{ |
88
|
|
|
$img = TrueColorImage::create(10, 10); |
89
|
|
|
$handle = $img->getHandle(); |
90
|
|
|
|
91
|
|
|
$this->assertTrue(WideImage::isValidImageHandle($handle)); |
92
|
|
|
|
93
|
|
|
$img = null; |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->assertFalse(WideImage::isValidImageHandle($handle)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testAutoDestruct() |
99
|
|
|
{ |
100
|
|
|
$img = TrueColorImage::create(10, 10); |
101
|
|
|
$handle = $img->getHandle(); |
102
|
|
|
|
103
|
|
|
unset($img); |
104
|
|
|
|
105
|
|
|
$this->assertFalse(WideImage::isValidImageHandle($handle)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testAutoDestructWithRelease() |
109
|
|
|
{ |
110
|
|
|
$img = TrueColorImage::create(10, 10); |
111
|
|
|
$handle = $img->getHandle(); |
112
|
|
|
|
113
|
|
|
$img->releaseHandle(); |
114
|
|
|
unset($img); |
115
|
|
|
|
116
|
|
|
$this->assertTrue(WideImage::isValidImageHandle($handle)); |
117
|
|
|
imagedestroy($handle); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testCustomOpMagic() |
121
|
|
|
{ |
122
|
|
|
$img = TrueColorImage::create(10, 10); |
123
|
|
|
$result = $img->customOp(123, 'abc'); |
|
|
|
|
124
|
|
|
$this->assertTrue($result instanceof Image); |
125
|
|
|
$this->assertSame(CustomOp::$args[0], $img); |
126
|
|
|
$this->assertSame(CustomOp::$args[1], 123); |
127
|
|
|
$this->assertSame(CustomOp::$args[2], 'abc'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testCustomOpCaseInsensitive() |
131
|
|
|
{ |
132
|
|
|
$img = TrueColorImage::create(10, 10); |
133
|
|
|
$result = $img->CUSTomOP(123, 'abc'); |
|
|
|
|
134
|
|
|
$this->assertTrue($result instanceof Image); |
135
|
|
|
$this->assertSame(CustomOp::$args[0], $img); |
136
|
|
|
$this->assertSame(CustomOp::$args[1], 123); |
137
|
|
|
$this->assertSame(CustomOp::$args[2], 'abc'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testInternalOpCaseInsensitive() |
141
|
|
|
{ |
142
|
|
|
$img = TrueColorImage::create(10, 10); |
143
|
|
|
$result = $img->AUTOcrop(); |
144
|
|
|
$this->assertTrue($result instanceof Image); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testOutput() |
148
|
|
|
{ |
149
|
|
|
$tmp = WideImage::load(IMG_PATH . 'fgnl.jpg'); |
150
|
|
|
$img = new ImageForOutput($tmp->getHandle()); |
151
|
|
|
|
152
|
|
|
ob_start(); |
153
|
|
|
$img->output('png'); |
154
|
|
|
$data = ob_get_clean(); |
155
|
|
|
|
156
|
|
|
$this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/png'), $img->headers); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @group bug |
161
|
|
|
*/ |
162
|
|
|
public function testOutputJPG() |
163
|
|
|
{ |
164
|
|
|
$tmp = WideImage::load(IMG_PATH . 'fgnl.jpg'); |
165
|
|
|
$img = new ImageForOutput($tmp->getHandle()); |
166
|
|
|
ob_start(); |
167
|
|
|
$img->output('jpg'); |
168
|
|
|
$data = ob_get_clean(); |
169
|
|
|
$this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/jpg'), $img->headers); |
170
|
|
|
|
171
|
|
|
$tmp = WideImage::load(IMG_PATH . 'fgnl.jpg'); |
172
|
|
|
$img = new ImageForOutput($tmp->getHandle()); |
173
|
|
|
ob_start(); |
174
|
|
|
$img->output('jpeg'); |
175
|
|
|
$data = ob_get_clean(); |
176
|
|
|
$this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/jpg'), $img->headers); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function testCanvasInstance() |
180
|
|
|
{ |
181
|
|
|
$img = WideImage::load(IMG_PATH . 'fgnl.jpg'); |
182
|
|
|
$canvas1 = $img->getCanvas(); |
183
|
|
|
$this->assertTrue($canvas1 instanceof Canvas); |
184
|
|
|
$canvas2 = $img->getCanvas(); |
185
|
|
|
$this->assertTrue($canvas1 === $canvas2); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function testSerializeTrueColorImage() |
189
|
|
|
{ |
190
|
|
|
$img = WideImage::load(IMG_PATH . 'fgnl.jpg'); |
191
|
|
|
$img2 = unserialize(serialize($img)); |
192
|
|
|
$this->assertEquals(get_class($img2), get_class($img)); |
193
|
|
|
$this->assertTrue($img2->isTrueColor()); |
194
|
|
|
$this->assertTrue($img2->isValid()); |
195
|
|
|
$this->assertFalse($img2->isTransparent()); |
196
|
|
|
$this->assertEquals($img->getWidth(), $img2->getWidth()); |
197
|
|
|
$this->assertEquals($img->getHeight(), $img2->getHeight()); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function testSerializePaletteImage() |
201
|
|
|
{ |
202
|
|
|
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); |
203
|
|
|
$img2 = unserialize(serialize($img)); |
204
|
|
|
$this->assertEquals(get_class($img2), get_class($img)); |
205
|
|
|
$this->assertFalse($img2->isTrueColor()); |
206
|
|
|
$this->assertTrue($img2->isValid()); |
207
|
|
|
$this->assertTrue($img2->isTransparent()); |
208
|
|
|
$this->assertEquals($img->getWidth(), $img2->getWidth()); |
209
|
|
|
$this->assertEquals($img->getHeight(), $img2->getHeight()); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|