1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Del\Image\Strategy;
|
4
|
|
|
|
5
|
|
|
class PngStrategy implements ImageTypeStrategyInterface
|
6
|
|
|
{
|
7
|
|
|
/**
|
8
|
|
|
* @param string $filename
|
9
|
|
|
* @return resource
|
10
|
|
|
*/
|
11
|
10 |
|
public function create($filename)
|
12
|
|
|
{
|
13
|
10 |
|
return imagecreatefrompng($filename);
|
14
|
|
|
}
|
15
|
|
|
|
16
|
|
|
/**
|
17
|
|
|
* @param resource $resource
|
18
|
|
|
* @param string $filename
|
19
|
|
|
* @param int $compression
|
20
|
|
|
* @return void
|
21
|
|
|
*/
|
22
|
1 |
|
public function save($resource, $filename, $compression)
|
23
|
|
|
{
|
24
|
1 |
|
unset($compression);
|
25
|
1 |
|
imagepng($resource, $filename);
|
26
|
1 |
|
}
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* @return string
|
30
|
|
|
*/
|
31
|
1 |
|
public function getContentType()
|
32
|
|
|
{
|
33
|
1 |
|
return 'image/png';
|
34
|
|
|
}
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* @param $resource
|
38
|
|
|
*/
|
39
|
7 |
|
public function render($resource)
|
40
|
|
|
{
|
41
|
7 |
|
imagealphablending($resource, true);
|
42
|
7 |
|
imagesavealpha($resource, true);
|
43
|
7 |
|
imagepng($resource);
|
44
|
7 |
|
}
|
45
|
|
|
|
46
|
4 |
|
public function handleTransparency($newImage, $image)
|
47
|
|
|
{
|
48
|
|
|
// Set blending mode as false
|
49
|
4 |
|
imagealphablending($newImage, false);
|
50
|
|
|
|
51
|
|
|
// Tell it we want to save alpha channel info
|
52
|
4 |
|
imagesavealpha($newImage, true);
|
53
|
|
|
|
54
|
|
|
// Set the transparent color
|
55
|
4 |
|
$color = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
|
56
|
|
|
|
57
|
|
|
// Fill the image with nothingness
|
58
|
4 |
|
imagefill($newImage, 0, 0, $color);
|
59
|
|
|
}
|
60
|
|
|
} |