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
|
|
|
} |