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

AbstractTransparentImage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepWithExistingIndex() 0 13 1
A prepTransparentPng() 0 13 1
A getTransparencyIndex() 0 3 1
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class AbstractTransparentImage
6
{
7
    /**
8
     * @param resource $newImage
9
     * @param resource $image
10
     * @param int $index
11
     */
12
    protected function prepWithExistingIndex($newImage, $image, $index)
13
    {
14
        // Get the array of RGB vals for the transparency index
15
        $transparentColor = imagecolorsforindex($image, $index);
16
17
        // Now allocate the color
18
        $transparency = imagecolorallocate($newImage, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']);
19
20
        // Fill the background with the color
21
        imagefill($newImage, 0, 0, $transparency);
22
23
        // And set that color as the transparent one
24
        imagecolortransparent($newImage, $transparency);
25
    }
26
27
    /**
28
     * @param $resource
29
     */
30 6
    protected function prepTransparentPng($resource)
31
    {
32
        // Set blending mode as false
33 6
        imagealphablending($resource, false);
34
35
        // Tell it we want to save alpha channel info
36 6
        imagesavealpha($resource, true);
37
38
        // Set the transparent color
39 6
        $color = imagecolorallocatealpha($resource, 0, 0, 0, 127);
40
41
        // Fill the image with nothingness
42 6
        imagefill($resource, 0, 0, $color);
43 6
    }
44
45
    /**
46
     * @param resource $image
47
     * @return int
48
     */
49 6
    protected function getTransparencyIndex($image)
50
    {
51 6
        return imagecolortransparent($image);
52
    }
53
}