Passed
Push — master ( 8ad17e...5319fe )
by Derek Stephen
02:06
created

PngStrategy::getContentType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
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
}