Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Color.php
1
<?php
9
namespace
Bitrix\Main\File\Image
;
10
11
class
Color
12
{
13
protected
14
$red
,
15
$green
,
16
$blue
,
17
$alpha
;
18
26
public
function
__construct
(
$red
= 0,
$green
= 0,
$blue
= 0,
$alpha
= 1.0)
27
{
28
$this->
setRed
(
$red
)
29
->setGreen(
$green
)
30
->setBlue(
$blue
)
31
->setAlpha(
$alpha
);
32
}
33
39
public
static
function
createFromHex
($color)
40
{
41
$color = preg_replace(
"/[^a-f0-9]/is"
,
""
, $color);
42
if
(strlen($color) != 6)
43
{
44
$color =
"FF0000"
;
45
}
46
47
return
new
static
(
48
hexdec(substr($color, 0, 2)),
49
hexdec(substr($color, 2, 2)),
50
hexdec(substr($color, 4, 2))
51
);
52
}
53
58
public
function
toHex
()
59
{
60
return
sprintf(
"#%02x%02x%02x"
, $this->
getRed
(), $this->
getGreen
(), $this->
getBlue
());
61
}
62
67
public
function
toRgba
()
68
{
69
return
sprintf(
"rgba(%d, %d, %d, %0.4f)"
, $this->
getRed
(), $this->
getGreen
(), $this->
getBlue
(), $this->
getAlpha
());
70
}
71
75
public
function
getRed
()
76
{
77
return
$this->red
;
78
}
79
84
public
function
setRed
(
$red
)
85
{
86
if
($red < 0 || $red > 255)
87
{
88
$red
= 0;
89
}
90
$this->red = (int)
$red
;
91
return
$this;
92
}
93
97
public
function
getGreen
()
98
{
99
return
$this->green
;
100
}
101
106
public
function
setGreen
(
$green
)
107
{
108
if
($green < 0 || $green > 255)
109
{
110
$green
= 0;
111
}
112
$this->green = (int)
$green
;
113
return
$this;
114
}
115
119
public
function
getBlue
()
120
{
121
return
$this->blue
;
122
}
123
128
public
function
setBlue
(
$blue
)
129
{
130
if
($blue < 0 || $blue > 255)
131
{
132
$blue
= 0;
133
}
134
$this->blue = (int)
$blue
;
135
return
$this;
136
}
137
141
public
function
getAlpha
()
142
{
143
return
$this->alpha
;
144
}
145
150
public
function
setAlpha
(
$alpha
)
151
{
152
$this->alpha = (float)
$alpha
;
153
return
$this;
154
}
155
}
Bitrix\Main\File\Image\Color
Definition
Color.php:12
Bitrix\Main\File\Image\Color\$red
$red
Definition
Color.php:14
Bitrix\Main\File\Image\Color\getRed
getRed()
Definition
Color.php:75
Bitrix\Main\File\Image\Color\__construct
__construct($red=0, $green=0, $blue=0, $alpha=1.0)
Definition
Color.php:26
Bitrix\Main\File\Image\Color\$green
$green
Definition
Color.php:15
Bitrix\Main\File\Image\Color\$alpha
$alpha
Definition
Color.php:17
Bitrix\Main\File\Image\Color\toHex
toHex()
Definition
Color.php:58
Bitrix\Main\File\Image\Color\toRgba
toRgba()
Definition
Color.php:67
Bitrix\Main\File\Image\Color\setGreen
setGreen($green)
Definition
Color.php:106
Bitrix\Main\File\Image\Color\createFromHex
static createFromHex($color)
Definition
Color.php:39
Bitrix\Main\File\Image\Color\$blue
$blue
Definition
Color.php:16
Bitrix\Main\File\Image\Color\setRed
setRed($red)
Definition
Color.php:84
Bitrix\Main\File\Image\Color\getGreen
getGreen()
Definition
Color.php:97
Bitrix\Main\File\Image\Color\getBlue
getBlue()
Definition
Color.php:119
Bitrix\Main\File\Image\Color\setAlpha
setAlpha($alpha)
Definition
Color.php:150
Bitrix\Main\File\Image\Color\setBlue
setBlue($blue)
Definition
Color.php:128
Bitrix\Main\File\Image\Color\getAlpha
getAlpha()
Definition
Color.php:141
Bitrix\Main\File\Image
Definition
Color.php:9
modules
main
lib
File
Image
Color.php
Создано системой
1.10.0