/** * Creates a color that can be accessed in this object. * * When a color is set, the integer resource of it is returned. * * @param string $name The name of the color. * @param integer $alpha Alpha transparency (0 - 127). * * @return integer The resource of the color that can be passed to GD. */ private function _allocateColor($name, $alpha = 0) { if (empty($this->_colors[$name])) { if ($name == 'none') { $this->_colors[$name] = $this->call('imageColorAllocateAlpha', array($this->_im, 0, 0, 0, 127)); } else { list($r, $g, $b) = Horde_Image::getRGB($name); $this->_colors[$name] = $this->call('imageColorAllocateAlpha', array($this->_im, $r, $g, $b, $alpha)); } } return $this->_colors[$name]; }
/** * Draws a rectangle. * * @param integer $x The left x-coordinate of the rectangle. * @param integer $y The top y-coordinate of the rectangle. * @param integer $width The width of the rectangle. * @param integer $height The height of the rectangle. * @param string $color The line color of the rectangle. * @param string $fill The color to fill the rectangle. */ public function rectangle($x, $y, $width, $height, $color = 'black', $fill = 'none') { list($r, $g, $b) = Horde_Image::getRGB($color); if ($fill != 'none') { list($fR, $fG, $fB) = Horde_Image::getRGB($fill); } $x2 = $x + $width; $y2 = $y + $height; for ($h = $y; $h <= $y2; $h++) { for ($w = $x; $w <= $x2; $w++) { // See if we're on an edge. if ($w == $x || $h == $y || $w == $x2 || $h == $y2) { $this->_img[$h][$w] = array('r' => $r, 'g' => $g, 'b' => $b); } elseif ($fill != 'none') { $this->_img[$h][$w] = array('r' => $fR, 'g' => $fG, 'b' => $fB); } } } }
/** * Creates a color that can be accessed in this object. * * When a color is set, the rgba values are returned in an array. * * @param string $name The name of the color. * * @return array The red, green, blue, alpha values of the color. */ public function allocateColor($name) { list($r, $g, $b) = Horde_Image::getRGB($name); return array('red' => $r, 'green' => $g, 'blue' => $b, 'alpha' => 255); }