I want to modify 2 imagick objects from the same iterator eg using the docs example
$imagick = new \Imagick(realpath($imagePath));
$imagick2 = clone $imagick;
$imageIterator = new \ImagickPixelIterator($imagick);
/* Loop through pixel rows */
foreach ($imageIterator as $pixels) {
/* Loop through the pixels in the row (columns) */
foreach ($pixels as $column => $pixel) {
/** @var $pixel \ImagickPixel */
if ($column % 2) {
/* Paint every second pixel black*/
$pixel->setColor("rgba(0, 0, 0, 0)");
} else {
//do something to $imagick2 here
$pixel->setColor("rgba(255, 255, 255, 0)");
}
}
/* Sync the iterator, this is important to do on each iteration */
$imageIterator->syncIterator();
is this possible and what would the syntax look like?
The iterators are standard PHP iterators, so the can be iterated through manually using the function
next()
andcurrent()
and checking that it is still valid withvalid()
.So something like this 'should' work.