private function _blendScreen($canvas, $gd1, $gd2, $loopStartY, $loopEndY, $loopStartX, $loopEndX, $offsetX, $offsetY, $opacity)
{
for ($y = $loopStartY; $y <= $loopEndY; $y++) {
for ($x = $loopStartX; $x <= $loopEndX; $x++) {
$canvasX = $x + $offsetX;
$canvasY = $y + $offsetY;
$argb1 = imagecolorat($gd1, $canvasX, $canvasY);
$r1 = $argb1 >> 16 & 0xff;
$g1 = $argb1 >> 8 & 0xff;
$b1 = $argb1 & 0xff;
$argb2 = imagecolorat($gd2, $x, $y);
$a2 = $argb2 >> 24 & 0x7f;
// 127 in hex. These are binary operations.
$r2 = $argb2 >> 16 & 0xff;
$g2 = $argb2 >> 8 & 0xff;
$b2 = $argb2 & 0xff;
$r3 = 255 - (255 - $r1) * (255 - $r2) / 255;
$g3 = 255 - (255 - $g1) * (255 - $g2) / 255;
$b3 = 255 - (255 - $b1) * (255 - $b2) / 255;
$reverse = 127 - $a2;
$reverse = round($reverse * $opacity);
$argb3 = imagecolorallocatealpha($canvas, $r3, $g3, $b3, 127 - $reverse);
imagesetpixel($canvas, $canvasX, $canvasY, $argb3);
}
}
return $canvas;
}