-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.php
executable file
·51 lines (43 loc) · 1.41 KB
/
color.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace PMVC\PlugIn\color;
use PMVC\PlugIn\image\ImageFile;
\PMVC\l(__DIR__ . '/src/BaseColor');
${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\color';
class color extends \PMVC\PlugIn
{
public function getPalette($file)
{
\PMVC\l(__DIR__ . '/src/ColorPalette.php');
$image = new ImageFile($file);
return ColorPalette::GenerateFromLocalImage($image);
}
public function getColor($r = null, $g = null, $b = null, $a = null)
{
return new BaseColor($r, $g, $b, $a);
}
public function fill($oGd, BaseColor $bgColor)
{
$pImg = \PMVC\plug('image');
imagefill($pImg->getGd($oGd), 0, 0, $bgColor->toGd($oGd));
}
public function hexToRgb($hex)
{
$hex = str_replace('#', '', $hex);
switch (strlen($hex)) {
case 3:
$r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
$g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
$b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
break;
case 6:
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
break;
default:
return !trigger_error('[HexToRgb] color length not correct');
break;
}
return new BaseColor($r, $g, $b);
}
}