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

GifStrategy::handleTransparency()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class GifStrategy extends AbstractTransparentImage implements ImageTypeStrategyInterface
6
{
7
    /**
8
     * @param string $filename
9
     * @return resource
10
     */
11 3
    public function create($filename)
12
    {
13 3
        return imagecreatefromgif($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
        imagegif($resource, $filename);
26 1
    }
27
28
    /**
29
     * @return string
30
     */
31 1
    public function getContentType()
32
    {
33 1
        return 'image/gif';
34
    }
35
36
    /**
37
     * @param $resource
38
     */
39 2
    public function render($resource)
40
    {
41 2
        imagegif($resource);
42 2
    }
43
44
    public function handleTransparency($newImage, $image)
45
    {
46
        // Get transparency color's index number
47
        $transparency = $this->getTransparencyIndex($image);
48
49
        // Is a strange index other than -1 set?
50
        if ($transparency >= 0) {
51
52
            // deal with alpha channels
53
            $this->prepWithExistingIndex($newImage, $image, $transparency);
54
55
        }
56
    }
57
58
59
}