Completed
Pull Request — master (#21)
by Chad
05:04
created

ImageTest::stripHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TraderInteractive\Util;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Util\Image
9
 */
10
final class ImageTest extends TestCase
11
{
12
    private $sourceFilesDir;
13
    private $tempDir;
14
15
    public function setUp()
16
    {
17
        $this->sourceFilesDir = __DIR__ . '/_files';
18
        $this->tempDir = sys_get_temp_dir() . '/imageUtilTest';
19
        if (is_dir($this->tempDir)) {
20
            foreach (glob("{$this->tempDir}/*") as $file) {
21
                unlink($file);
22
            }
23
24
            rmdir($this->tempDir);
25
        }
26
    }
27
28
    /**
29
     * Downsize ratio 2.0 to 0.25
30
     *
31
     * @test
32
     * @covers ::resize
33
     * @covers ::resizeMulti
34
     */
35
    public function resizeDownsizeToMoreVerticalAspect()
36
    {
37
        $source = new \Imagick('pattern:gray0');
38
        $source->scaleImage(100, 50);
39
40
        $imagick = Image::resize($source, 10, 40, ['color' => 'white', 'maxWidth' => 10000, 'maxHeight' => 10000]);
41
42
        //making sure source didnt resize
43
        $this->assertSame(100, $source->getImageWidth());
44
        $this->assertSame(50, $source->getImageHeight());
45
46
        $this->assertSame(10, $imagick->getImageWidth());
47
        $this->assertSame(40, $imagick->getImageHeight());
48
49
        $whiteBarTop = $imagick->getImagePixelColor(4, 16)->getHsl();
50
        $whiteBarBottom = $imagick->getImagePixelColor(4, 22)->getHsl();
51
52
        $imageLeft = $imagick->getImagePixelColor(0, 19)->getHsl();
53
        $imageRight = $imagick->getImagePixelColor(9, 19)->getHsl();
54
        $imageTop = $imagick->getImagePixelColor(4, 17)->getHsl();
55
        $imageBottom = $imagick->getImagePixelColor(4, 21)->getHsl();
56
57
        $this->assertGreaterThan(0.9, $whiteBarTop['luminosity']);
58
        $this->assertGreaterThan(0.9, $whiteBarBottom['luminosity']);
59
60
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
61
        $this->assertLessThan(0.1, $imageRight['luminosity']);
62
        $this->assertLessThan(0.1, $imageTop['luminosity']);
63
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
64
    }
65
66
    /**
67
     * Downsize ratio 2.0 to 4.0
68
     *
69
     * @test
70
     * @covers ::resize
71
     * @covers ::resizeMulti
72
     */
73 View Code Duplication
    public function resizeDownsizeToMoreHorizontalAspect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $source = new \Imagick('pattern:gray0');
76
        $source->scaleImage(100, 50);
77
78
        $imagick = Image::resize($source, 40, 10);
79
80
        //making sure source didnt resize
81
        $this->assertSame(100, $source->getImageWidth());
82
        $this->assertSame(50, $source->getImageHeight());
83
84
        $this->assertSame(40, $imagick->getImageWidth());
85
        $this->assertSame(10, $imagick->getImageHeight());
86
87
        $whiteBarLeft = $imagick->getImagePixelColor(9, 4)->getHsl();
88
        $whiteBarRight = $imagick->getImagePixelColor(30, 4)->getHsl();
89
90
        $imageLeft = $imagick->getImagePixelColor(10, 4)->getHsl();
91
        $imageRight = $imagick->getImagePixelColor(29, 4)->getHsl();
92
        $imageTop = $imagick->getImagePixelColor(19, 0)->getHsl();
93
        $imageBottom = $imagick->getImagePixelColor(19, 9)->getHsl();
94
95
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
96
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
97
98
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
99
        $this->assertLessThan(0.1, $imageRight['luminosity']);
100
        $this->assertLessThan(0.1, $imageTop['luminosity']);
101
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
102
    }
103
104
    /**
105
     * Upsize ratio 2.0 to 4.0
106
     *
107
     * @test
108
     * @covers ::resize
109
     * @covers ::resizeMulti
110
     */
111 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithoutGrow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $source = new \Imagick('pattern:gray0');
114
        $source->scaleImage(100, 50);
115
116
        $imagick = Image::resize($source, 400, 100);
117
118
        //making sure source didnt resize
119
        $this->assertSame(100, $source->getImageWidth());
120
        $this->assertSame(50, $source->getImageHeight());
121
122
        $this->assertSame(400, $imagick->getImageWidth());
123
        $this->assertSame(100, $imagick->getImageHeight());
124
125
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
126
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
127
128
        $imageTop = $imagick->getImagePixelColor(200, 26)->getHsl();
129
        $imageBottom = $imagick->getImagePixelColor(200, 74)->getHsl();
130
        $imageLeft = $imagick->getImagePixelColor(151, 50)->getHsl();
131
        $imageRight = $imagick->getImagePixelColor(249, 50)->getHsl();
132
133
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
134
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
135
136
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
137
        $this->assertLessThan(0.1, $imageRight['luminosity']);
138
        $this->assertLessThan(0.1, $imageTop['luminosity']);
139
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
140
    }
141
142
    /**
143
     * Upsize ratio 2.0 to 4.0
144
     *
145
     * @test
146
     * @covers ::resize
147
     * @covers ::resizeMulti
148
     */
149 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithGrow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    {
151
        $source = new \Imagick('pattern:gray0');
152
        $source->scaleImage(100, 50);
153
154
        $imagick = Image::resize($source, 400, 100, ['upsize' => true]);
155
156
        //making sure source didnt resize
157
        $this->assertSame(100, $source->getImageWidth());
158
        $this->assertSame(50, $source->getImageHeight());
159
160
        $this->assertSame(400, $imagick->getImageWidth());
161
        $this->assertSame(100, $imagick->getImageHeight());
162
163
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
164
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
165
166
        $imageTop = $imagick->getImagePixelColor(249, 0)->getHsl();
167
        $imageBottom = $imagick->getImagePixelColor(249, 99)->getHsl();
168
        $imageLeft = $imagick->getImagePixelColor(100, 49)->getHsl();
169
        $imageRight = $imagick->getImagePixelColor(299, 49)->getHsl();
170
171
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
172
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
173
174
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
175
        $this->assertLessThan(0.1, $imageRight['luminosity']);
176
        $this->assertLessThan(0.1, $imageTop['luminosity']);
177
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
178
    }
179
180
    /**
181
     * Upsize ratio 2.0 to 4.0
182
     *
183
     * @test
184
     * @covers ::resize
185
     * @covers ::resizeMulti
186
     */
187 View Code Duplication
    public function resizeUpsizeToMoreVerticalAspect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
    {
189
        $source = new \Imagick('pattern:gray0');
190
        $source->scaleImage(100, 50);
191
192
        $imagick = Image::resize($source, 200, 400);
193
194
        //making sure source didnt resize
195
        $this->assertSame(100, $source->getImageWidth());
196
        $this->assertSame(50, $source->getImageHeight());
197
198
        $this->assertSame(200, $imagick->getImageWidth());
199
        $this->assertSame(400, $imagick->getImageHeight());
200
201
        $whiteBarLeft = $imagick->getImagePixelColor(49, 200)->getHsl();
202
        $whiteBarRight = $imagick->getImagePixelColor(151, 200)->getHsl();
203
204
        $imageTop = $imagick->getImagePixelColor(100, 176)->getHsl();
205
        $imageBottom = $imagick->getImagePixelColor(100, 224)->getHsl();
206
        $imageLeft = $imagick->getImagePixelColor(51, 200)->getHsl();
207
        $imageRight = $imagick->getImagePixelColor(149, 200)->getHsl();
208
209
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
210
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
211
212
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
213
        $this->assertLessThan(0.1, $imageRight['luminosity']);
214
        $this->assertLessThan(0.1, $imageTop['luminosity']);
215
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
216
    }
217
218
    /**
219
     * @test
220
     * @covers ::resize
221
     * @covers ::resizeMulti
222
     */
223
    public function resizeWithUpsizeAndBestFit()
224
    {
225
        $source = new \Imagick('pattern:gray0');
226
        $source->scaleImage(85, 45);
227
        $notBestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => false]);
228
        $this->assertSame('srgb(0,0,0)', $notBestFit->getImagePixelColor(299, 100)->getColorAsString());
229
        $bestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => true]);
230
        $this->assertSame('srgb(255,255,255)', $bestFit->getImagePixelColor(299, 100)->getColorAsString());
231
    }
232
233
    /**
234
     * @test
235
     * @covers ::resize
236
     * @covers ::resizeMulti
237
     */
238
    public function resizeWithBurredBackground()
239
    {
240
        $source = new \Imagick();
241
        $source->readImage(__DIR__ . '/_files/portrait.jpg');
242
        $imagick = Image::resize($source, 1024, 768, ['upsize' => true, 'bestfit' => false, 'color' => 'blur']);
243
        $expectedBytes = file_get_contents(__DIR__ . '/_files/blur.jpg');
244
        $this->assertSame($imagick->getImageBlob(), $expectedBytes);
245
    }
246
247
    /**
248
     * @test
249
     * @covers ::resize
250
     * @covers ::resizeMulti
251
     * @expectedException \InvalidArgumentException
252
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
253
     */
254
    public function resizeZeroBoxWidth()
255
    {
256
        Image::resize(new \Imagick(), 0, 10);
257
    }
258
259
    /**
260
     * @test
261
     * @covers ::resize
262
     * @covers ::resizeMulti
263
     * @expectedException \InvalidArgumentException
264
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
265
     */
266
    public function resizeLargeBoxWidth()
267
    {
268
        Image::resize(new \Imagick(), 10001, 10, ['maxWidth' => 10000]);
269
    }
270
271
    /**
272
     * @test
273
     * @covers ::resize
274
     * @covers ::resizeMulti
275
     * @expectedException \InvalidArgumentException
276
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
277
     */
278
    public function resizeZeroBoxHeight()
279
    {
280
        Image::resize(new \Imagick(), 10, 0);
281
    }
282
283
    /**
284
     * @test
285
     * @covers ::resize
286
     * @covers ::resizeMulti
287
     * @expectedException \InvalidArgumentException
288
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
289
     */
290
    public function resizeLargeBoxHeight()
291
    {
292
        Image::resize(new \Imagick(), 10, 10001, ['maxHeight' => 10000]);
293
    }
294
295
    /**
296
     * @test
297
     * @covers ::resize
298
     * @covers ::resizeMulti
299
     * @expectedException \InvalidArgumentException
300
     * @expectedExceptionMessage $options["color"] was not a string
301
     */
302
    public function resizeNonStringColor()
303
    {
304
        Image::resize(new \Imagick(), 10, 10, ['color' => 0]);
305
    }
306
307
    /**
308
     * @test
309
     * @covers ::resize
310
     * @covers ::resizeMulti
311
     * @expectedException \InvalidArgumentException
312
     * @expectedExceptionMessage $options["maxWidth"] was not an int
313
     */
314
    public function resizeonIntMaxWidth()
315
    {
316
        Image::resize(new \Imagick(), 10, 10, ['maxWidth' => 'not int']);
317
    }
318
319
    /**
320
     * @test
321
     * @covers ::resize
322
     * @covers ::resizeMulti
323
     * @expectedException \InvalidArgumentException
324
     * @expectedExceptionMessage $options["maxHeight"] was not an int
325
     */
326
    public function resizeNonIntMaxHeight()
327
    {
328
        Image::resize(new \Imagick(), 10, 10, ['maxHeight' => 'not int']);
329
    }
330
331
    /**
332
     * @test
333
     * @covers ::resize
334
     * @covers ::resizeMulti
335
     * @expectedException \InvalidArgumentException
336
     * @expectedExceptionMessage $options["upsize"] was not a bool
337
     */
338
    public function resizeNonBoolUpsize()
339
    {
340
        Image::resize(new \Imagick(), 10, 10, ['upsize' => 'not bool']);
341
    }
342
343
    /**
344
     * @test
345
     * @covers ::resize
346
     * @covers ::resizeMulti
347
     * @expectedException \InvalidArgumentException
348
     * @expectedExceptionMessage $options["bestfit"] was not a bool
349
     */
350
    public function resizeNonBoolBestFit()
351
    {
352
        Image::resize(new \Imagick(), 10, 10, ['bestfit' => 'not bool']);
353
    }
354
355
    /**
356
     * Verify images are rotated according to EXIF header
357
     * @test
358
     * @covers ::resize
359
     * @covers ::resizeMulti
360
     */
361
    public function resizeOrientation()
362
    {
363
        $files = [
364
            "{$this->sourceFilesDir}/bottom-right.jpg",
365
            "{$this->sourceFilesDir}/left-bottom.jpg",
366
            "{$this->sourceFilesDir}/right-top.jpg",
367
            "{$this->sourceFilesDir}/top-left.jpg",
368
        ];
369
370
        $imageResults = [];
371
372
        foreach ($files as $file) {
373
            $source = new \Imagick($file);
374
            $imageWidth = $source->getimagewidth();
375
            $imageHeight = $source->getimageheight();
376
            $imageResults[] = Image::resize($source, $imageWidth, $imageHeight, []);
377
        }
378
379
        $this->assertSame(
380
            ['r' => 254, 'g' => 0, 'b' => 0, 'a' => 1],
381
            $imageResults[0]->getImagePixelColor(0, 0)->getColor()
382
        );
383
        $this->assertSame(
384
            ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 1],
385
            $imageResults[1]->getImagePixelColor(0, 0)->getColor()
386
        );
387
        $this->assertSame(
388
            ['r' => 0, 'g' => 255, 'b' => 1, 'a' => 1],
389
            $imageResults[2]->getImagePixelColor(0, 0)->getColor()
390
        );
391
        $this->assertSame(
392
            ['r' => 0, 'g' => 0, 'b' => 254, 'a' => 1],
393
            $imageResults[3]->getImagePixelColor(0, 0)->getColor()
394
        );
395
    }
396
397
    /**
398
     * Downsize ratio 2.0 to 0.25 and 2.0 to 4.0
399
     *
400
     * @test
401
     * @covers ::resizeMulti
402
     */
403
    public function resizeMultiDownsizeToMoreVerticalAndMoreHorizontalAspect()
404
    {
405
        $source = new \Imagick('pattern:gray0');
406
        $source->scaleImage(100, 50);
407
408
        $results = Image::resizeMulti($source, [['width' => 10, 'height' => 40], ['width' => 40, 'height' => 10]]);
409
        $imagickOne = $results[0];
410
        $imagickTwo = $results[1];
411
412
        //making sure source didnt resize
413
        $this->assertSame(100, $source->getImageWidth());
414
        $this->assertSame(50, $source->getImageHeight());
415
416
        //check $imagick1
417
418
        $this->assertSame(10, $imagickOne->getImageWidth());
419
        $this->assertSame(40, $imagickOne->getImageHeight());
420
421
        $oneWhiteBarTop = $imagickOne->getImagePixelColor(4, 16)->getHsl();
422
        $oneWhiteBarBottom = $imagickOne->getImagePixelColor(4, 22)->getHsl();
423
424
        $oneImageLeft = $imagickOne->getImagePixelColor(0, 19)->getHsl();
425
        $oneImageRight = $imagickOne->getImagePixelColor(9, 19)->getHsl();
426
        $oneImageTop = $imagickOne->getImagePixelColor(4, 17)->getHsl();
427
        $oneImageBottom = $imagickOne->getImagePixelColor(4, 21)->getHsl();
428
429
        $this->assertGreaterThan(0.9, $oneWhiteBarTop['luminosity']);
430
        $this->assertGreaterThan(0.9, $oneWhiteBarBottom['luminosity']);
431
432
        $this->assertLessThan(0.1, $oneImageLeft['luminosity']);
433
        $this->assertLessThan(0.1, $oneImageRight['luminosity']);
434
        $this->assertLessThan(0.1, $oneImageTop['luminosity']);
435
        $this->assertLessThan(0.1, $oneImageBottom['luminosity']);
436
437
        //check $imagick2
438
439
        $this->assertSame(40, $imagickTwo->getImageWidth());
440
        $this->assertSame(10, $imagickTwo->getImageHeight());
441
442
        $twoWhiteBarLeft = $imagickTwo->getImagePixelColor(9, 4)->getHsl();
443
        $twoWhiteBarRight = $imagickTwo->getImagePixelColor(30, 4)->getHsl();
444
445
        $twoImageLeft = $imagickTwo->getImagePixelColor(10, 4)->getHsl();
446
        $twoImageRight = $imagickTwo->getImagePixelColor(29, 4)->getHsl();
447
        $twoImageTop = $imagickTwo->getImagePixelColor(19, 0)->getHsl();
448
        $twoImageBottom = $imagickTwo->getImagePixelColor(19, 9)->getHsl();
449
450
        $this->assertGreaterThan(0.9, $twoWhiteBarLeft['luminosity']);
451
        $this->assertGreaterThan(0.9, $twoWhiteBarRight['luminosity']);
452
453
        $this->assertLessThan(0.1, $twoImageLeft['luminosity']);
454
        $this->assertLessThan(0.1, $twoImageRight['luminosity']);
455
        $this->assertLessThan(0.1, $twoImageTop['luminosity']);
456
        $this->assertLessThan(0.1, $twoImageBottom['luminosity']);
457
    }
458
459
    /**
460
     * @test
461
     * @covers ::resizeMulti
462
     */
463
    public function resizeMultiPerformance()
464
    {
465
        $source = new \Imagick('pattern:gray0');
466
        $source->scaleImage(2000, 500);
467
468
        $count = 10;
469
470
        $beforeSingle = microtime(true);
471
        for ($i = 0; $i < $count; ++$i) {
472
            Image::resize($source, 1100, 400);
473
            Image::resize($source, 100, 400);
474
            Image::resize($source, 10, 40);
475
        }
476
477
        $singleTime = microtime(true) - $beforeSingle;
478
479
        $beforeMulti = microtime(true);
480
        for ($i = 0; $i < $count; ++$i) {
481
            Image::resizeMulti(
482
                $source,
483
                [['width' => 1100, 'height' => 400], ['width' => 100, 'height' => 400], ['width' => 10, 'height' => 40]]
484
            );
485
        }
486
487
        $multiTime = microtime(true) - $beforeMulti;
488
489
        $this->assertLessThan($singleTime, $multiTime * 0.75);
490
    }
491
492
    /**
493
     * @test
494
     * @covers ::resizeMulti
495
     * @expectedException \InvalidArgumentException
496
     * @expectedExceptionMessage a width in a $boxSizes value was not an int
497
     */
498
    public function resizeMultiNonIntWidth()
499
    {
500
        Image::resizeMulti(new \Imagick(), [['width' => true, 'height' => 10]]);
501
    }
502
503
    /**
504
     * @test
505
     * @covers ::resizeMulti
506
     * @expectedException \InvalidArgumentException
507
     * @expectedExceptionMessage a height in a $boxSizes value was not an int
508
     */
509
    public function resizeMultiNonIntHeight()
510
    {
511
        Image::resizeMulti(new \Imagick(), [['width' => 10, 'height' => true]]);
512
    }
513
514
    /**
515
     * @test
516
     * @covers ::write
517
     */
518
    public function write()
519
    {
520
        $destPath = "{$this->tempDir}/dest.jpeg";
521
522
        $source = new \Imagick("{$this->sourceFilesDir}/exif.jpg");
523
        $source->setImageFormat('png');
524
525
        Image::write(
526
            $source,
527
            $destPath,
528
            ['format' => 'jpeg', 'directoryMode' => 0775, 'fileMode' => 0776, 'stripHeaders' => true]
529
        );
530
531
        $destImage = new \Imagick($destPath);
532
533
        $this->assertSame(0, count($destImage->getImageProperties('exif:*')));
534
        $this->assertSame('JPEG', $destImage->getImageFormat());
535
536
        $directoryPermissions = substr(sprintf('%o', fileperms($this->tempDir)), -4);
537
        $filePermissions = substr(sprintf('%o', fileperms($destPath)), -4);
538
539
        $this->assertSame('0775', $directoryPermissions);
540
        $this->assertSame('0776', $filePermissions);
541
    }
542
543
    /**
544
     * @test
545
     * @covers ::write
546
     * @expectedException \InvalidArgumentException
547
     * @expectedExceptionMessage $options["directoryMode"] was not an int
548
     */
549
    public function writeNonIntDirectoryMode()
550
    {
551
        Image::write(new \Imagick(), 'not under test', ['directoryMode' => 'not int']);
552
    }
553
554
    /**
555
     * @test
556
     * @covers ::write
557
     * @expectedException \InvalidArgumentException
558
     * @expectedExceptionMessage $options["fileMode"] was not an int
559
     */
560
    public function writeNonIntFileMode()
561
    {
562
        Image::write(new \Imagick(), 'not under test', ['fileMode' => 'not int']);
563
    }
564
565
    /**
566
     * @test
567
     * @covers ::write
568
     * @expectedException \InvalidArgumentException
569
     * @expectedExceptionMessage $options["format"] was not a string
570
     */
571
    public function writeNonStringFormat()
572
    {
573
        Image::write(new \Imagick(), 'not under test', ['format' => true]);
574
    }
575
576
    /**
577
     * @test
578
     * @covers ::write
579
     * @expectedException \InvalidArgumentException
580
     * @expectedExceptionMessage $options["stripHeaders"] was not a bool
581
     */
582
    public function writeNonBoolStripHeaders()
583
    {
584
        Image::write(new \Imagick(), 'not under test', ['stripHeaders' => 'not bool']);
585
    }
586
587
    /**
588
     * Verify that stripHeaders strips exif headers.
589
     *
590
     * @test
591
     * @covers ::stripHeaders
592
     */
593
    public function stripHeaders()
594
    {
595
        $path = "{$this->tempDir}/stripHeaders.jpg";
596
597
        mkdir($this->tempDir);
598
        copy("{$this->sourceFilesDir}/exif.jpg", $path);
599
600
        Image::stripHeaders($path);
601
602
        $imagick = new \Imagick($path);
603
        $this->assertSame(0, count($imagick->getImageProperties('exif:*')));
604
    }
605
606
    /**
607
     * Verify that stripHeaders fails with a missing image.
608
     *
609
     * @test
610
     * @covers ::stripHeaders
611
     * @expectedException \ImagickException
612
     */
613
    public function stripHeadersMissingImage()
614
    {
615
        Image::stripHeaders("{$this->tempDir}/doesnotexist.jpg");
616
    }
617
}
618