note 71765 added to function.imagealphablending
| From: | JAYPEEsorenATgeeMail at osu1 dot php dot net | Date: | Thu, 14 Dec 2006 21:52:07 +0000 |
| Subject: | note 71765 added to function.imagealphablending | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120615@lists.php.net to get a copy of this message | ||
I rewrote the code given below to skip calculations and pixel setting when not needed (full opaque
or full transparent pixels), as the content of my overlays is generally mostly transparent. Reduced
processing time from ~0.17s to ~0.06s on 216x145px images.
function alphaOverlay($destImg, $overlayImg, $imgW, $imgH)
{
for($y=0;$y<$imgH;$y++)
{
for($x=0;$x<$imgW;$x++)
{
$ovrARGB = imagecolorat($overlayImg, $x, $y);
$ovrA = ($ovrARGB >> 24) << 1;
$ovrR = $ovrARGB >> 16 & 0xFF;
$ovrG = $ovrARGB >> 8 & 0xFF;
$ovrB = $ovrARGB & 0xFF;
$change = false;
if($ovrA == 0)
{
$dstR = $ovrR;
$dstG = $ovrG;
$dstB = $ovrB;
$change = true;
}
elseif($ovrA < 254)
{
$dstARGB = imagecolorat($destImg, $x, $y);
$dstR = $dstARGB >> 16 & 0xFF;
$dstG = $dstARGB >> 8 & 0xFF;
$dstB = $dstARGB & 0xFF;
$dstR = (($ovrR * (0xFF-$ovrA)) >> 8) + (($dstR * $ovrA) >> 8);
$dstG = (($ovrG * (0xFF-$ovrA)) >> 8) + (($dstG * $ovrA) >> 8);
$dstB = (($ovrB * (0xFF-$ovrA)) >> 8) + (($dstB * $ovrA) >> 8);
$change = true;
}
if($change)
{
$dstRGB = imagecolorallocatealpha($destImg, $dstR, $dstG, $dstB, 0);
imagesetpixel($destImg, $x, $y, $dstRGB);
}
}
}
return $destImg;
}
----
Server IP: 216.194.113.175
Probable Submitter: 207.173.178.2 (proxied: 207.173.178.102)
----
Manual Page -- http://www.php.net/manual/en/function.imagealphablending.php
Edit -- https://master.php.net/note/edit/71765
Del: integrated -- https://master.php.net/note/delete/71765/integrated
Del: useless -- https://master.php.net/note/delete/71765/useless
Del: bad code -- https://master.php.net/note/delete/71765/bad+code
Del: spam -- https://master.php.net/note/delete/71765/spam
Del: non-english -- https://master.php.net/note/delete/71765/non-english
Del: in docs -- https://master.php.net/note/delete/71765/in+docs
Del: other reasons-- https://master.php.net/note/delete/71765
Reject -- https://master.php.net/note/reject/71765
Search -- https://master.php.net/manage/user-notes.php