I’m trying to implement this code snippet (a “vignette” effect) with Imagick, but the processing is incredibly slow:
set_time_limit(90);
$iterator = $imagick->getPixelIterator();
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
foreach($iterator as $y => $pixels){
foreach($pixels as $x => $pixel){
$l = 1 - 0.7 * (1 - pow((sin(M_PI / $width * $x) * sin(M_PI / $height * $y)), 0.4));
extract($pixel->getColor());
$pixel->setColor(sprintf('rgb(%d,%d,%d)', $r * $l, $g * $l, $b * $l));
}
$iterator->syncIterator();
}
Original:

Result:

For a 1600×1200 image, it takes like 35 seconds for image to be processed. Is there a better way to do this?
What you are doing is over kill ImageMagic already has
-vignettecommandOriginal
Final Output