Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public final function getColor(PointInterface $position)
 {
     $l = $this->getDistance($position);
     if ($l >= $this->length) {
         return $this->end;
     }
     if ($l < 0) {
         return $this->start;
     }
     $color = new Color(array((int) min(255, min($this->start->getRed(), $this->end->getRed()) + round(abs($this->end->getRed() - $this->start->getRed()) * $l / $this->length)), (int) min(255, min($this->start->getGreen(), $this->end->getGreen()) + round(abs($this->end->getGreen() - $this->start->getGreen()) * $l / $this->length)), (int) min(255, min($this->start->getBlue(), $this->end->getBlue()) + round(abs($this->end->getBlue() - $this->start->getBlue()) * $l / $this->length))), (int) min(100, min($this->start->getAlpha(), $this->end->getAlpha()) + round(abs($this->end->getAlpha() - $this->start->getAlpha()) * $l / $this->length)));
     return $color;
 }
Exemplo n.º 2
0
 /**
  * @cover Imagine\Image\Color::__construct
  * @cover Imagine\Image\Color::getRed
  * @cover Imagine\Image\Color::getGreen
  * @cover Imagine\Image\Color::getAlpha
  * @cover Imagine\Image\Color::__toString
  * @cover Imagine\Image\Color::isOpaque
  */
 public function testShouldSetColorToWhite()
 {
     $color = new Color('fff');
     $this->assertEquals(255, $color->getRed());
     $this->assertEquals(255, $color->getGreen());
     $this->assertEquals(255, $color->getBlue());
     $this->assertEquals(0, $color->getAlpha());
     $this->assertEquals('#ffffff', (string) $color);
     $this->assertEquals('#00ff00', (string) new Color('00ff00'));
     $this->assertTrue($color->isOpaque());
 }
Exemplo n.º 3
0
 /**
  * Gets specifically formatted color string from Color instance
  *
  * @param Color $color
  *
  * @return string
  */
 private function getColor(Color $color)
 {
     if (!$color->isOpaque()) {
         throw new InvalidArgumentException('Gmagick doesn\'t support transparency');
     }
     $pixel = new \GmagickPixel((string) $color);
     $pixel->setColorValue(\Gmagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1));
     return $pixel;
 }
Exemplo n.º 4
0
 /**
  * Gets specifically formatted color string from Color instance
  *
  * @param Color $color
  *
  * @return string
  */
 private function getColor(Color $color)
 {
     $pixel = new \ImagickPixel((string) $color);
     $pixel->setColorValue(\Imagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1));
     return $pixel;
 }
Exemplo n.º 5
0
 /**
  * Internal
  *
  * Generates a GD color from Color instance
  *
  * @param Color $color
  *
  * @return resource
  *
  * @throws RuntimeException
  */
 private function getColor(Color $color)
 {
     $index = imagecolorallocatealpha($this->resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100));
     if (false === $index) {
         throw new RuntimeException(sprintf('Unable to allocate color "RGB(%s, %s, %s)" with transparency ' . 'of %d percent', $color->getRed(), $color->getGreen(), $color->getBlue(), $color->getAlpha()));
     }
     return $index;
 }
Exemplo n.º 6
0
    /**
     * Internal
     *
     * Generates a GD color from Color instance
     *
     * @param  Imagine\Image\Color $color
     *
     * @return resource
     *
     * @throws Imagine\Exception\RuntimeException
     */
    private function getColor(Color $color)
    {
        static $cache = array();

        $key = (string) $color . "-" . $color->getAlpha();

        if (!isset($cache[$key])) {
            $cache[$key] = imagecolorallocatealpha(
                $this->resource, $color->getRed(), $color->getGreen(),
                $color->getBlue(), round(127 * $color->getAlpha() / 100)
            );
        }

        if (false === $cache[$key]) {
            throw new RuntimeException(sprintf(
                'Unable to allocate color "RGB(%s, %s, %s)" with transparency '.
                'of %d percent', $color->getRed(), $color->getGreen(),
                $color->getBlue(), $color->getAlpha()
            ));
        }

        return $cache[$key];
    }