]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/stil/gd-text/src/Color.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / stil / gd-text / src / Color.php
1 <?php
2 namespace GDText;
3
4 class Color
5 {
6     /**
7      * @var int
8      */
9     protected $red;
10
11     /**
12      * @var int
13      */
14     protected $green;
15
16     /**
17      * @var int
18      */
19     protected $blue;
20
21     /**
22      * @var int|null
23      */
24     protected $alpha;
25
26     /**
27      * @param int $red Value of red component 0-255
28      * @param int $green Value of green component 0-255
29      * @param int $blue Value of blue component 0-255
30      * @param int $alpha A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent.
31      */
32     public function __construct($red = 0, $green = 0, $blue = 0, $alpha = null)
33     {
34         $this->red = $red;
35         $this->green = $green;
36         $this->blue = $blue;
37         $this->alpha = $alpha;
38     }
39
40     /**
41      * @param resource $image GD image resource
42      * @return int Returns the index of the specified color+alpha in the palette of the image,
43      *             or -1 if the color does not exist in the image's palette.
44      */
45     public function getIndex($image)
46     {
47         if ($this->hasAlphaChannel()) {
48             return imagecolorexactalpha(
49                 $image,
50                 $this->red,
51                 $this->green,
52                 $this->blue,
53                 $this->alpha
54             );
55         } else {
56             return imagecolorexact(
57                 $image,
58                 $this->red,
59                 $this->green,
60                 $this->blue
61             );
62         }
63     }
64
65     /**
66      * @return bool TRUE when alpha channel is specified, FALSE otherwise
67      */
68     public function hasAlphaChannel()
69     {
70         return $this->alpha !== null;
71     }
72 }