There would be no setImagePixelColor
method on the Imagick
class. I can't speak of why there isn't one, but one can achieve the same effects by invoking the ImagickPixelIterator, or ImagickDraw class.
Iterator Example:
The proper way would be to iterator over the pixels in an image, alter a pixels color, then sync the data back to the image.
$image = new Imagick('source.png');
// Grab iterator
$iterator = $image->getPixelIterator();
// Seek to row at Y
$iterator->setIteratorRow($j);
// Get pixel in row
$row = $iterator->getCurrentIteratorRow();
// Seek to pixel at X
$pixel = $row[$i];
// Set Color
$pixel->setColor('#FFFFFF');
// Sync data back to image
$iterator->syncIterator();
$image->writeImage('out.png');
Draw Example:
The other option would be to draw the new pixel on top of the existing image.
$image = new Imagick('source.png');
$draw = new ImagickDraw();
$color = new ImagickPixel('#FFFFFF');
// Set fill color
$draw->setFillColor($color);
// Draw a point at X,Y
$draw->point($i,$j);
// Apply the drawing on top of the image
$image->drawImage($draw);
$image->writeImage('dest.png');
Of course with Object's in PHP, you can simple extend the core Imagick object, and create your own setImagePixelColor
method
class MyImagick extends Imagick
{
/**
* Alter image by defining the color of a single pixel
*
* @param integer $x
* @param integer $y
* @param string $color
*/
public function setImagePixelColor($x,$y, $color)
{
//... Apply one of the methods here
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel($color));
$draw->point($x,$y);
$this->drawImage($draw);
}
}