123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class WebColor {
-
-
-
- var $red = 0;
- var $green = 0;
- var $blue = 0;
-
- function __construct($color = null)
- {
- if (isset($color)) {
- $this->parseColor($color);
- }
- }
-
- function parseColor($color) {
- if (is_numeric($color)) {
- $this->setIntColor($color);
- } else {
-
-
- if (preg_match('/(#([0-9A-Fa-f]{3,6})\b)/u', $color) > 0) {
- $this->setHexColor($color);
- } else {
-
-
- $errmsg = _('%s is not a valid color! Use 3 or 6 hex characters.');
- throw new WebColorException(sprintf($errmsg, $color));
- }
- }
- }
-
- function setNamedColor($name)
- {
-
- }
-
- function setHexColor($hexcolor) {
- if ($hexcolor[0] == '#') {
- $hexcolor = substr($hexcolor, 1);
- }
- if (strlen($hexcolor) == 6) {
- list($r, $g, $b) = array($hexcolor[0].$hexcolor[1],
- $hexcolor[2].$hexcolor[3],
- $hexcolor[4].$hexcolor[5]);
- } elseif (strlen($hexcolor) == 3) {
- list($r, $g, $b) = array($hexcolor[0].$hexcolor[0],
- $hexcolor[1].$hexcolor[1],
- $hexcolor[2].$hexcolor[2]);
- } else {
-
-
- $errmsg = _('%s is not a valid color! Use 3 or 6 hex characters.');
- throw new WebColorException(sprintf($errmsg, $hexcolor));
- }
- $this->red = hexdec($r);
- $this->green = hexdec($g);
- $this->blue = hexdec($b);
- }
-
- function setIntColor($intcolor)
- {
-
-
- $this->red = $intcolor >> 16;
- $this->green = $intcolor >> 8 & 0xFF;
- $this->blue = $intcolor & 0xFF;
- }
-
- function hexValue() {
- $hexcolor = (strlen(dechex($this->red)) < 2 ? '0' : '' ) .
- dechex($this->red);
- $hexcolor .= (strlen(dechex($this->green)) < 2 ? '0' : '') .
- dechex($this->green);
- $hexcolor .= (strlen(dechex($this->blue)) < 2 ? '0' : '') .
- dechex($this->blue);
- return strtoupper($hexcolor);
- }
-
- function intValue()
- {
- $intcolor = 256 * 256 * $this->red + 256 * $this->green + $this->blue;
- return $intcolor;
- }
- }
- class WebColorException extends Exception
- {
- }
|