HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

ImagickPixel::setColorFromPixel

← setColor   setColorValue →

Sets the color of one ImagickPixel from another ImagickPixel object.

This method is included for completeness; the underlying function is useful in the C programming language but in PHP it is easy to copy values around.


Example

function setColorFromPixel()
{
    $image = new \Imagick();
    $draw = new \ImagickDraw();

    $stroke_color = new \ImagickPixel('black');

    $fill_color = new \ImagickPixel('red');
    $blue_color = new \ImagickPixel('blue');

    $fill_color->setColorFromPixel($blue_color);

    $draw->setstrokewidth(1.0);
    $draw->setStrokeColor($stroke_color);
    $draw->setFillColor($fill_color);
    $draw->rectangle(200, 200, 300, 300);

    $image->newImage(500, 500, "gray");
    $image->setImageFormat("png");
    $image->drawImage($draw);

    header("Content-Type: image/png");
    echo $image->getImageBlob();
}