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

PngStrategy::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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