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 }
/** * Add a Block to a pixel to a given coordinate depending * on a pixels color * * @param \ImagickPixel $pixel * @param Structure $structure * @param $x * @param $y * @param $z */ protected function addBlockForPixel(\ImagickPixel $pixel, Structure $structure, $x, $y, $z) { $color = $pixel->getColor(); $type = $this->blockTypeColorMapping->getBlockTypeForRgbColor($color['r'], $color['g'], $color['b']); if (null === $type) { return; } // if meta is null it becomes 0 $meta = (int) $type->getMeta(); $structure->createBlock($type->getName(), array('x' => $x, 'y' => $y, 'z' => $z), $meta); }
function render() { $output = "<table class='smallPadding' width='100%'>"; $output .= "<tbody>"; foreach ($this->listOfColors as $color) { $pixelColor = new \ImagickPixel($color); $colorArray = $pixelColor->getColor(); if ($color == 'transparent' || $color == 'none') { $rgbaString = sprintf("rgb(%d, %d, %d, %d)", $colorArray['r'], $colorArray['g'], $colorArray['b'], $colorArray['a']); $hexString = sprintf("#%02x%02x%02x%02x", $colorArray['r'], $colorArray['g'], $colorArray['b'], $colorArray['a']); } else { $rgbaString = sprintf("rgb(%d, %d, %d)", $colorArray['r'], $colorArray['g'], $colorArray['b']); $hexString = sprintf("#%02x%02x%02x", $colorArray['r'], $colorArray['g'], $colorArray['b']); } $colorString = ''; if ($colorArray['r'] + $colorArray['g'] + $colorArray['b'] < 200) { if ($colorArray['a'] != 0) { $colorString = 'color: #efefef'; } } $output .= "<tr>"; $output .= "<td>"; $output .= $color; $output .= "</td>"; $output .= "<td style='background-color: {$hexString};{$colorString}'>"; $output .= $color; $output .= "</td>"; $output .= "<td>"; $output .= $rgbaString; $output .= "</td>"; $output .= "<td>"; $output .= $hexString; $output .= "</td>"; $output .= "</tr>"; } $output .= "</tbody>"; $output .= "</table>"; return $output; }
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==
/** * @param \ImagickPixel $px * @param array $pixels * @param int $x * @param int $y * * @return float */ private function getColor($px, &$pixels, $x, $y) { if (isset($pixels[$x][$y])) { return $pixels[$x][$y]; } $rgba = $px->getColor(); return $pixels[$x][$y] = round($rgba['r'] * 0.3 + $rgba['g'] * 0.59 + $rgba['b'] * 0.11); // gray }