public function render()
 {
     //Example ImagickPixel::getColorValue
     $color = new \ImagickPixel('rgba(90%, 20%, 20%, 0.75)');
     echo "Alpha value is " . $color->getColorValue(\Imagick::COLOR_ALPHA) . "<br/>";
     echo "" . "<br/>";
     echo "Red value is " . $color->getColorValue(\Imagick::COLOR_RED) . "<br/>";
     echo "Green value is " . $color->getColorValue(\Imagick::COLOR_GREEN) . "<br/>";
     echo "Blue value is " . $color->getColorValue(\Imagick::COLOR_BLUE) . "<br/>";
     echo "" . "<br/>";
     echo "Cyan value is " . $color->getColorValue(\Imagick::COLOR_CYAN) . "<br/>";
     echo "Magenta value is " . $color->getColorValue(\Imagick::COLOR_MAGENTA) . "<br/>";
     echo "Yellow value is " . $color->getColorValue(\Imagick::COLOR_YELLOW) . "<br/>";
     echo "Black value is " . $color->getColorValue(\Imagick::COLOR_BLACK) . "<br/>";
     //Example end
 }
Exemple #2
0
 /**
  * Returns a color given a pixel, depending the Palette context
  *
  * Note : this method is public for PHP 5.3 compatibility
  *
  * @param \ImagickPixel $pixel
  *
  * @return ColorInterface
  *
  * @throws InvalidArgumentException In case a unknown color is requested
  */
 public function pixelToColor(\ImagickPixel $pixel)
 {
     static $colorMapping = array(ColorInterface::COLOR_RED => \Imagick::COLOR_RED, ColorInterface::COLOR_GREEN => \Imagick::COLOR_GREEN, ColorInterface::COLOR_BLUE => \Imagick::COLOR_BLUE, ColorInterface::COLOR_CYAN => \Imagick::COLOR_CYAN, ColorInterface::COLOR_MAGENTA => \Imagick::COLOR_MAGENTA, ColorInterface::COLOR_YELLOW => \Imagick::COLOR_YELLOW, ColorInterface::COLOR_KEYLINE => \Imagick::COLOR_BLACK, ColorInterface::COLOR_GRAY => \Imagick::COLOR_RED);
     $alpha = $this->palette->supportsAlpha() ? (int) round($pixel->getColorValue(\Imagick::COLOR_ALPHA) * 100) : null;
     $palette = $this->palette();
     return $this->palette->color(array_map(function ($color) use($palette, $pixel, $colorMapping) {
         if (!isset($colorMapping[$color])) {
             throw new InvalidArgumentException(sprintf('Color %s is not mapped in Imagick', $color));
         }
         $multiplier = 255;
         if ($palette->name() === PaletteInterface::PALETTE_CMYK) {
             $multiplier = 100;
         }
         return $pixel->getColorValue($colorMapping[$color]) * $multiplier;
     }, $this->palette->pixelDefinition()), $alpha);
 }
Exemple #3
0
<?php

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==
Exemple #4
0
 /**
  * Returns a color given a pixel, depending the Palette context
  *
  * Note : this method is public for PHP 5.3 compatibility
  *
  * @param \ImagickPixel $pixel
  *
  * @return ColorInterface
  *
  * @throws InvalidArgumentException In case a unknown color is requested
  */
 public function pixelToColor(\ImagickPixel $pixel)
 {
     static $colorMapping = array(ColorInterface::COLOR_RED => \Imagick::COLOR_RED, ColorInterface::COLOR_GREEN => \Imagick::COLOR_GREEN, ColorInterface::COLOR_BLUE => \Imagick::COLOR_BLUE, ColorInterface::COLOR_CYAN => \Imagick::COLOR_CYAN, ColorInterface::COLOR_MAGENTA => \Imagick::COLOR_MAGENTA, ColorInterface::COLOR_YELLOW => \Imagick::COLOR_YELLOW, ColorInterface::COLOR_KEYLINE => \Imagick::COLOR_BLACK);
     $alpha = $this->palette->supportsAlpha() ? (int) round($pixel->getColorValue(\Imagick::COLOR_ALPHA) * 100) : null;
     return $this->palette->color(array_map(function ($color) use($pixel, $colorMapping) {
         if (!isset($colorMapping[$color])) {
             throw new InvalidArgumentException('Color %s is not mapped in Imagick');
         }
         return $pixel->getColorValue($colorMapping[$color]) * 255;
     }, $this->palette->pixelDefinition()), $alpha);
 }
 /**
  * Returns RGB alpha value of current color
  *
  * @return float
  */
 public function getAlphaValue()
 {
     return round($this->pixel->getColorValue(\Imagick::COLOR_ALPHA), 2);
 }
Exemple #6
0
        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==