* @author Jesper Veggerby <*****@*****.**> */ $file = file('./data/colors.txt'); require_once 'Image/Canvas.php'; require_once 'Image/Graph/Color.php'; require_once 'Image/Graph/Constants.php'; $Canvas =& Image_Canvas::factory('gd', array('width' => 600, 'height' => 1200)); $i = 0; $cols = 10; $Width = $Canvas->getWidth() / $cols; $rows = count($file) / $cols; $rows = floor($rows) + ($rows > floor($rows) ? 1 : 0); $Height = $Canvas->getHeight() / $rows; while (list($id, $color) = each($file)) { $color = trim($color); $x = $i % $cols * $Width + $Width / 2; $y = floor($i / $cols) * $Height; $Canvas->setLineColor('black'); $Canvas->setFillColor($color); $Canvas->rectangle($x - $Width / 4, $y, $x + $Width / 4, $y + $Height / 3); $Canvas->write($x, $y + $Height / 3 + 3, $color, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_TOP); $rgbColor = Image_Graph_Color::color2RGB($color); $rgbs = 'RGB: '; unset($rgbColor[3]); while (list($id, $rgb) = each($rgbColor)) { $rgbs .= ($rgb < 0x10 ? '0' : '') . dechex($rgb); } $Canvas->write($x, $y + $Height / 3 + 13, $rgbs, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_TOP); $i++; } $Canvas->done();
/** * Add a color. * This method adds a color to the graph. This causes the GD image to allocate the color * if necessary (i.e. using GD1 TrueColor images are not supported). This is not necessary * perhaps use {@see Image_Graph::newColor()} or the named color constants. * @param Image_Graph_Color $color A representation of the color */ function &addColor(& $color) { $color->_setParent($this); $this->_colors[] = & $color; return $color; }