/** * (non-PHPdoc) * @see Imagine\Image\ImagineInterface::create() */ public function create(BoxInterface $size, Color $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); $color = null !== $color ? $color : new Color('fff'); try { $pixel = new \ImagickPixel((string) $color); $pixel->setColorValue( \Imagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1) ); $imagick = new \Imagick(); $imagick->newImage($width, $height, $pixel); $imagick->setImageMatte(true); $imagick->setImageBackgroundColor($pixel); $pixel->clear(); $pixel->destroy(); return new Image($imagick); } catch (\ImagickException $e) { throw new RuntimeException( 'Could not create empty image', $e->getCode(), $e ); } }
public function render() { //Example ImagickPixel::getColorAsString $output = "Create an ImagickPixel with the predefined color 'brown' and output the result of `getColorAsString`. <br/>"; $color = new \ImagickPixel('brown'); $color->setColorValue(\Imagick::COLOR_ALPHA, 64 / 256.0); $output .= $color->getColorAsString(); return $output; //Example end }
public function render() { echo "Create an ImagickPixel with the predefined color 'brown' and set the color to have an alpha of 25% <br/>"; //Example ImagickPixel::getColor $color = new \ImagickPixel('brown'); $color->setColorValue(\Imagick::COLOR_ALPHA, 0.25); echo "<h4>Standard values</h4>" . PHP_EOL; foreach ($color->getColor() as $key => $value) { echo "{$key} : {$value} <br/>"; } echo "<br/>"; echo "<h4>Normalized values</h4>" . PHP_EOL; foreach ($color->getColor(true) as $key => $value) { echo "{$key} : {$value} <br/>"; } //Example end }
public function create(BoxInterface $size, ColorInterface $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); $color = self::getColor($color); try { $pixel = new \ImagickPixel($color['color']); $pixel->setColorValue(\Imagick::COLOR_OPACITY, $color['alpha']); $magick = new \Imagick(); $magick->newImage($width, $height, $pixel); $magick->setImageMatte(true); $magick->setImageBackgroundColor($pixel); $pixel->clear(); $pixel->destroy(); return new RImage($magick, $color['palette'], self::$emptyBag, array($width, $height)); } catch (\Exception $e) { throw new \Imagine\Exception\RuntimeException("Imagick: Could not create empty image {$e->getMessage()}", $e->getCode(), $e); } }
/** * Set/get background color. Check Imagick::COLOR_* constants * * @param int|string|array $color * @return int */ public function backgroundColor($color = null) { if ($color) { if (is_array($color)) { $color = "rgb(" . join(',', $color) . ")"; } $pixel = new \ImagickPixel(); if (is_numeric($color)) { $pixel->setColorValue($color, 1); } else { $pixel->setColor($color); } if ($this->_imageHandler) { $this->_imageHandler->setImageBackgroundColor($color); } } else { $pixel = $this->_imageHandler->getImageBackgroundColor(); } $this->imageBackgroundColor = $pixel->getColorAsString(); return $this->imageBackgroundColor; }
public function rotate($angle, \Imagine\Image\Palette\Color\ColorInterface $background = null) { if ($this->image === null) { $this->load(); } $color = RImagine::getColor($background); try { $pixel = new \ImagickPixel($color['color']); $pixel->setColorValue(\Imagick::COLOR_OPACITY, $color['alpha']); $magick = $this->image->getImagick(); $magick->rotateimage($pixel, $angle); $pixel->clear(); $pixel->destroy(); $magick->setImagePage(0, 0, 0, 0); // reset canvas position } catch (\ImagickException $e) { throw new \Imagine\Exception\RuntimeException('Imagick: Rotate operation failed. ' . $e->getMessage(), $e->getCode(), $e); } $this->size = array($magick->getImageWidth(), $magick->getImageHeight()); return $this; }
/** * {@inheritdoc} */ public function create(BoxInterface $size, ColorInterface $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); $palette = null !== $color ? $color->getPalette() : new RGB(); $color = null !== $color ? $color : $palette->color('fff'); try { $pixel = new \ImagickPixel((string) $color); $pixel->setColorValue(Imagick::COLOR_ALPHA, $color->getAlpha() / 100); $imagick = new Imagick(); $imagick->newImage($width, $height, $pixel); $imagick->setImageMatte(true); $imagick->setImageBackgroundColor($pixel); if (version_compare('6.3.1', $this->getVersion($imagick)) < 0) { $imagick->setImageOpacity($pixel->getColorValue(Imagick::COLOR_ALPHA)); } $pixel->clear(); $pixel->destroy(); return new Image($imagick, $palette, new MetadataBag()); } catch (\ImagickException $e) { throw new RuntimeException('Could not create empty image', $e->getCode(), $e); } }
/** * Gets specifically formatted color string from Color instance * * @param ColorInterface $color * * @return \ImagickPixel */ private function getColor(ColorInterface $color) { $pixel = new \ImagickPixel((string) $color); $pixel->setColorValue(\Imagick::COLOR_ALPHA, $color->getAlpha() / 100); return $pixel; }
/** * Gets specifically formatted color string from Color instance * * @param ColorInterface $color * * @return \ImagickPixel */ private function getColor(ColorInterface $color) { $pixel = new \ImagickPixel((string) $color); $pixel->setColorValue(\Imagick::COLOR_ALPHA, number_format(round($color->getAlpha() / 100, 2), 1)); return $pixel; }
/** * 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; }
try { $pixel = new ImagickPixel('the-best-color-in-the-world'); } catch (ImagickPixelException $ex) { echo "__construct\n"; } $pixel = new ImagickPixel('white'); try { $pixel->setColor('the-worst-color-in-the-world'); } catch (ImagickPixelException $ex) { echo "setColor\n"; } define('IMAGICK_COLOR_INVALID', -1); try { $pixel->getColorValue(IMAGICK_COLOR_INVALID); } catch (ImagickPixelException $ex) { echo "getColorValue\n"; } try { $pixel->setColorValue(IMAGICK_COLOR_INVALID, 0); } catch (ImagickPixelException $ex) { echo "setColorValue\n"; } try { $pixel->isPixelSimilar(new ImagickPixelException(), 0); } catch (ImagickPixelException $ex) { echo "isPixelSimilar\n"; } ?> ==DONE==
return sprintf('%.3f', $matches[0]); }, $ret); echo "{$ret}\n"; } $pixel = new ImagickPixel(); $pixel->setColor('yellow'); dump($pixel->getHSL()); dump($pixel->getColor(true)); $pixel = new ImagickPixel($pixel->getColorAsString()); dump($pixel->getHSL()); dump($pixel->getColor(false)); $pixel = new ImagickPixel(); $pixel->setHSL(0.3, 0.4, 0.5); dump($pixel->getHSL()); dump($pixel->getColor(false)); $pixel = new ImagickPixel($pixel->getColorAsString()); dump($pixel->getHSL()); dump($pixel->getColor(true)); $pixel = new ImagickPixel('#F02B88'); $colors = array(Imagick::COLOR_BLACK, Imagick::COLOR_BLUE, Imagick::COLOR_CYAN, Imagick::COLOR_GREEN, Imagick::COLOR_RED, Imagick::COLOR_YELLOW, Imagick::COLOR_MAGENTA, Imagick::COLOR_ALPHA, Imagick::COLOR_FUZZ); foreach ($colors as $color) { dump($pixel->getColorValue($color)); } foreach ($colors as $color) { $pixel->setColorValue($color, $pixel->getColorValue($color)); } dump($pixel->getHSL()); dump($pixel->getColor()); ?> ==DONE==