function render() { //Example ImagickPixel::setHSL $output = "This example creates a red color, rotates the hue by 180 degrees and sets the new color.<br/>"; //Create an almost pure red color $color = new \ImagickPixel('rgb(90%, 10%, 10%)'); $originalColor = clone $color; //Get it's HSL values $colorInfo = $color->getHSL(); //Rotate the hue by 180 degrees $newHue = $colorInfo['hue'] + 0.5; if ($newHue > 1) { $newHue = $newHue - 1; } //Set the ImagickPixel to the new color $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']); $output .= "<h3>Original color</h3>"; $colorInfo = $originalColor->getcolor(); foreach ($colorInfo as $key => $value) { $output .= "{$key} : {$value} <br/>"; } $output .= "<h3>Rotated color</h3>"; //Check that the new color is blue/green $colorInfo = $color->getcolor(); foreach ($colorInfo as $key => $value) { $output .= "{$key} : {$value} <br/>"; } return $output; //Example end }
public function render() { //Example ImagickPixel::getHSL $colorString = 'rgb(90%, 10%, 10%)'; $output = "The result of getHSL for the color '{$colorString}' is:<br/>"; $color = new \ImagickPixel($colorString); $colorInfo = $color->getHSL(); foreach ($colorInfo as $key => $value) { $output .= "{$key} : {$value} <br/>"; } return $output; //Example end }
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider) { $aniGif = new \Imagick(); $aniGif->setFormat("gif"); $width = 500; $height = $width; $numberDots = intval($numberDots); if ($numberDots < 1) { $numberDots = 1; } $maxFrames = $numberFrames; $frameDelay = ceil($loopTime / $maxFrames); $scale = 1; $startColor = new \ImagickPixel('red'); $dots = []; for ($i = 0; $i < $numberDots; $i++) { $colorInfo = $startColor->getHSL(); //Rotate the hue by 180 degrees $newHue = $colorInfo['hue'] + $i / $numberDots; if ($newHue > 1) { $newHue = $newHue - 1; } //Set the ImagickPixel to the new color $color = new \ImagickPixel('#ffffff'); $colorInfo['saturation'] *= 0.95; $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']); $dots[] = new Dot($color, $i, $numberDots, $width, $height); } for ($frame = 0; $frame < $maxFrames; $frame++) { $draw = new \ImagickDraw(); $draw->setStrokeColor('none'); $draw->setFillColor('none'); $draw->rectangle(0, 0, $width, $height); $draw->translate($width / 2, $height / 2); foreach ($dots as $dot) { /** @var $dot Dot */ $dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider); } //Create an image object which the draw commands can be rendered into $imagick = new \Imagick(); $imagick->newImage($width * $scale, $height * $scale, $backgroundColor); $imagick->setImageFormat("png"); $imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS); //Render the draw commands in the ImagickDraw object //into the image. $imagick->drawImage($draw); $imagick->setImageDelay($frameDelay); $aniGif->addImage($imagick); $imagick->destroy(); } $aniGif->setImageFormat('gif'); $aniGif->setImageIterations(0); //loop forever $aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS); header("Content-Type: image/gif"); echo $aniGif->getImagesBlob(); }
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==