public function testInvalidColor() { $strColor = '-invalid-'; $color = new Color($strColor); $this->assertEquals($strColor, $color->getColor()); $this->assertEquals(255, $color->getRed()); $this->assertEquals(255, $color->getGreen()); $this->assertEquals(255, $color->getBlue()); $this->assertEquals(0, $color->getAlpha()); }
/** * @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 */ 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')); }
/** * @param \DarkLuk42\Color $color * @param bool $forceAllocation * * @return int */ public function getColorIndex(Color $color, $forceAllocation = true) { if ($color->hasAlpha()) { $index = imagecolorexactalpha($this->image, $color->getRed(), $color->getGreen(), $color->getBlue(), intval($color->getAlpha() / 2)); } else { $index = imagecolorexact($this->image, $color->getRed(), $color->getGreen(), $color->getBlue()); } if ($index == -1 && $forceAllocation) { $index = $this->colorAllocate($color); } return $index; }