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

AbstractTransparentImage::getTransparencyIndex()   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
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
}