Completed
Push — master ( 8ba72f...a2bda9 )
by Derek Stephen
01:51
created

PngStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A create() 0 3 1
A getContentType() 0 3 1
A handleTransparency() 0 15 2
A render() 0 5 1
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class PngStrategy extends AbstractTransparentImage  implements ImageTypeStrategyInterface
6
{
7
    /**
8
     * @param string $filename
9
     * @return resource
10
     */
11 12
    public function create($filename)
12
    {
13 12
        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 9
    public function render($resource)
40
    {
41 9
        imagealphablending($resource, true);
42 9
        imagesavealpha($resource, true);
43 9
        imagepng($resource);
44 9
    }
45
46 6
    public function handleTransparency($newImage, $image)
47
    {
48
        // Get transparency color's index number
49 6
        $transparency = $this->getTransparencyIndex($image);
50
51
        // Is a strange index other than -1 set?
52 6
        if ($transparency >= 0) {
53
54
            // deal with alpha channels
55
            $this->prepWithExistingIndex($newImage, $image, $transparency);
56
57
        } else {
58
59
            // deal with alpha channels
60 6
            $this->prepTransparentPng($newImage);
61
        }
62
    }
63
}