/** * @access public * @static * @author Laurent Laville <*****@*****.**> */ function color2RGB($color) { $c = array(); if ($color[0] == '#') { $c = Image_Color::hex2rgb($color); } else { $c = Image_Color::namedColor2RGB($color); } return $c; }
/** * Draw all circle segment pictures * * @param string $dir (optional) Directory where pictures should be created * @param string $fileMask (optional) sprintf format for pictures filename * * @return array * @since 1.2.0RC1 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT */ function drawCircleSegments($dir = '.', $fileMask = 'c%s.png') { if (!is_string($dir)) { return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$dir', 'was' => gettype($dir), 'expected' => 'string', 'paramnum' => 1)); } elseif (!is_string($fileMask)) { return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$fileMask', 'was' => gettype($fileMask), 'expected' => 'string', 'paramnum' => 2)); } include_once 'Image/Color.php'; $cellAttr = $this->getCellAttributes(); $cellCount = $this->getCellCount(); $w = $cellAttr['width']; $h = $cellAttr['height']; $s = $cellAttr['spacing']; $c = intval(360 / $cellCount); $cx = floor($w / 2); if (fmod($w, 2) == 0) { $cx = $cx - 0.5; } $cy = floor($h / 2); if (fmod($h, 2) == 0) { $cy = $cy - 0.5; } $image = imagecreate($w, $h); $bg = Image_Color::allocateColor($image, $cellAttr['background-color']); $colorA = Image_Color::allocateColor($image, $cellAttr['active-color']); $colorI = Image_Color::allocateColor($image, $cellAttr['inactive-color']); imagefilledarc($image, $cx, $cy, $w, $h, 0, 360, $colorI, IMG_ARC_EDGED); $filename = $dir . DIRECTORY_SEPARATOR . sprintf($fileMask, 0); imagepng($image, $filename); $this->setCellAttributes(array('background-image' => $filename), 0); for ($i = 0; $i < $cellCount; $i++) { if ($this->getFillWay() == 'natural') { $sA = $i * $c; $eA = ($i + 1) * $c; $sI = ($i + 1) * $c; $eI = 360; } else { $sA = 360 - ($i + 1) * $c; $eA = 360 - $i * $c; $sI = 0; $eI = 360 - ($i + 1) * $c; } if ($s > 0) { imagefilledarc($image, $cx, $cy, $w, $h, 0, $sA, $colorI, IMG_ARC_EDGED); } imagefilledarc($image, $cx, $cy, $w, $h, $sA, $eA, $colorA, IMG_ARC_EDGED); imagefilledarc($image, $cx, $cy, $w, $h, $sI, $eI, $colorI, IMG_ARC_EDGED); $filename = $dir . DIRECTORY_SEPARATOR . sprintf($fileMask, $i + 1); imagepng($image, $filename); $this->setCellAttributes(array('background-image' => $filename), $i + 1); } imagedestroy($image); }
/** * build the epocLevel Array automatically by calculating an array of colors * * @param string $latestColor color of latest epocLevel (usually dark) * @param string $earliestColor color of earliest epocLevel (usually light) * @param int $thresholds number of levels to generate colors for * * @return array epocLevel * * @since Method available since Release 0.2.0 */ private function _generateEpocLevel($latestColor, $earliestColor, $thresholds) { include_once 'Image/Color.php'; $imageColor = new Image_Color(); $imageColor->setWebSafe(false); $imageColor->setColors($latestColor, $earliestColor); $epocLevel = array(); foreach ($imageColor->getRange($thresholds) as $key => $color) { $epocLevel[]['epocLevel' . $key] = array('link' => $color, 'visited' => $color); } return array_reverse($epocLevel); }
/** * getRange * Given a degree, you can get the range of colors between one color and * another color. * * @param string $degrees How much each 'step' between the colors we should take. * * @return array Array of all the colors, one element for each color. * @access public */ function getRange($degrees) { $tempColors = parent::getRange($degrees); // now add alpha-channel information $steps = count($tempColors); for ($counter = 0; $counter < $steps; $counter++) { $tempColors[$counter] = parent::hex2rgb($tempColors[$counter]); unset($tempColors[$counter]['hex']); $tempColors[$counter][3] = (int) round(((double) $this->color1[3] * ($steps - $counter) + (double) $this->color2[3] * $counter) / $steps); } return $tempColors; }
/** * Draws a clipped line from ($x1, $y1) to ($x2, $y2) * using $color. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param mixed $color * @access public */ function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || $y1 < $this->min['y']) && ($x2 > $this->max['x'] || $x2 < $this->min['x'] || $y2 > $this->max['y'] || $y2 < $this->min['y'])) { if ($this->debug) { printf('clipped x1: %d %d %d<br />', $x1, $this->min['x'], $this->max['x']); printf('clipped y1: %d %d %d<br />', $y1, $this->min['y'], $this->max['y']); printf('clipped x2: %d %d %d<br />', $x2, $this->min['x'], $this->max['x']); printf('clipped y2: %d %d %d<br />', $y2, $this->min['y'], $this->max['y']); } } else { if (!is_array($color)) { $color = Image_Color::namedColor2RGB($color); } $x1 = $this->polar2image($x1, 'x'); $y1 = $this->polar2image($y1, 'y'); $x2 = $this->polar2image($x2, 'x'); $y2 = $this->polar2image($y2, 'y'); if ($this->debug) { printf('Drawing line (%s, %s) -> (%s, %s)<br />', $x1, $y1, $x2, $y2); } $this->drawLine($x1, $y1, $x2, $y2, $color[0], $color[1], $color[2]); } }
case 'day': return_ofc_day(); break; case 'h24': return_ofc_24(); break; case 'cc': return_ofc_cc(); break; } exit; } // generate some colors for the activity bar $colors = ''; if ($ps->conf['theme']['map']['google_key']) { $c = new Image_Color(); $c->setColors('cc0000', '00cc00'); $range = $c->getRange(100, 1); foreach ($range as $i => $col) { $colors .= sprintf("<span id='color-%s'>%s</span>\n", $i, $col); } $colors .= "<span id='color-100'>00CC00</span>\n"; } // assign variables to the theme $cms->theme->assign(array('page' => basename($PHP_SELF, '.php'), 'activity_colors' => $colors)); // display the output $basename = basename(__FILE__, '.php'); if ($ps->conf['theme']['map']['google_key']) { $cms->theme->add_js('http://maps.google.com/maps?file=api&v=2&key=' . $ps->conf['theme']['map']['google_key']); // $cms->theme->add_js('http://www.google.com/jsapi?key=' . $ps->conf['theme']['map']['google_key']); $cms->theme->add_js('js/map.js');
function testPercentageColor2RGB_2digits() { $result = Image_Color::percentageColor2RGB("10%,50%,90%"); $this->assertEquals(array(26, 127, 229), $result); }
/** * Get nearest colors between mask color and unmask color using * antialias factor. * * @return array Colors range. * @access private */ function _getNearestColors() { $imcolor = new Image_Color(); $imcolor->setColors($this->options['mask_color'], $this->options['unmask_color']); return $imcolor->getRange($this->options['antialias_factor']); }
function pct_bar($args = array()) { global $cms; require_once dirname(__FILE__) . "/class_Color.php"; $args += array('pct' => 0, 'color1' => 'cc0000', 'color2' => '00cc00', 'degrees' => 1, 'width' => null, 'class' => 'pct-bar', 'styles' => '', 'title' => null); static $colors = array(); if (!empty($args['width']) and (!is_numeric($args['width']) or $args['width'] < 1)) { $args['width'] = 100; } $w = $args['width'] ? $args['width'] : 100; // $width = $args['pct'] / 100 * $w; // scaled width $key = $args['color1'] . ':' . $args['color2']; if (!$colors[$key]) { $c = new Image_Color(); $c->setColors($args['color1'], $args['color2']); $colors[$key] = $c->getRange(100, $args['degrees']); // 100 colors, no matter the width /** foreach ($colors[$key] as $col) { printf("<div style='color: white; background-color: %s'>%s</div>", $col, $col); } /**/ } $styles = !empty($args['styles']) ? $args['styles'] : ''; if (!empty($args['width'])) { $styles = " width: " . $args['width'] . "px;"; } if (!empty($styles)) { $styles = " style='{$styles}'"; } $out = sprintf("<span %s title='%s'%s><span style='width: %s; background-color: #%s'></span></span>", !empty($args['class']) ? "class='" . $args['class'] . "'" : "", !empty($args['title']) ? $args['title'] : (int) $args['pct'] . '%', $styles, (int) $args['pct'] . '%', $colors[$key][intval($args['pct']) - 1]); return $out; }
/** * hsv2rgb * Converts a HSV (Hue, Saturation, Brightness) value to RGB. * * @access public * @param integer $h Hue * @param integer $s Saturation * @param integer $v Brightness * @return string The RGB value. * @author Jason Lotito <*****@*****.**> */ function hsv2rgb($h, $s, $v) { return Image_Color::hex2rgb(Image_Color::hsv2hex($h, $s, $v)); }