-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathImageMergeTest.php
More file actions
96 lines (82 loc) · 2.61 KB
/
ImageMergeTest.php
File metadata and controls
96 lines (82 loc) · 2.61 KB
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
<?php
use PHPUnit\Framework\TestCase;
use SimpleSoftwareIO\QrCode\Image;
use SimpleSoftwareIO\QrCode\ImageMerge;
class ImageMergeTest extends TestCase
{
/**
* The location to save the testing image.
*
* @var string
*/
protected $testImageSaveLocation;
/**
* The location to save the compare image.
*
* @var string
*/
protected $compareTestSaveLocation;
/**
* The ImageMerge Object.
*
* @var ImageMerge
*/
protected $testImage;
/**
* The location of the test image that is having an image merged over top of it.
*
* @var string
*/
protected $testImagePath;
/**
* The location of the test image that is being merged.
* @var mixed
*/
protected $mergeImagePath;
public function setUp(): void
{
$this->testImagePath = file_get_contents(dirname(__FILE__).'/Images/simplesoftware-icon-grey-blue.png');
$this->mergeImagePath = file_get_contents(dirname(__FILE__).'/Images/200x300.png');
$this->testImage = new ImageMerge(
new Image($this->testImagePath),
new Image($this->mergeImagePath)
);
$this->testImageSaveLocation = dirname(__FILE__).'/testImage.png';
$this->compareTestSaveLocation = dirname(__FILE__).'/compareImage.png';
}
public function tearDown(): void
{
@unlink($this->testImageSaveLocation);
@unlink($this->compareTestSaveLocation);
}
public function test_it_merges_two_images_together_and_centers_it()
{
//We know the source image is 512x512 and the merge image is 200x300
$source = imagecreatefromstring($this->testImagePath);
$merge = imagecreatefromstring($this->mergeImagePath);
//Create a PNG and place the image in the middle using 20% of the area.
imagecopyresampled(
$source,
$merge,
205,
222,
0,
0,
102,
67,
536,
354
);
imagealphablending( $source, false );
imagesavealpha( $source, true );
imagepng($source, $this->compareTestSaveLocation);
$testImage = $this->testImage->merge(.2);
file_put_contents($this->testImageSaveLocation, $testImage);
$this->assertEquals(file_get_contents($this->compareTestSaveLocation), file_get_contents($this->testImageSaveLocation));
}
public function test_it_throws_an_exception_when_percentage_is_greater_than_1()
{
$this->expectException(InvalidArgumentException::class);
$this->testImage->merge(1.1);
}
}