note 63377 added to function.imageconvolution

From: Date: Tue, 21 Mar 2006 17:00:46 +0000
Subject: note 63377 added to function.imageconvolution
Groups: php.notes 
Request: Send a blank email to php-notes+get-106164@lists.php.net to get a copy of this message
I've seen many people come up with ways to do a drop shadow behind a rectangle such as a picture. I haven't found one yet that was fast, PHP 4 complaint, and nice looking. Here is one I came up with last night. It takes an image, fills it with the background, and creates a blurred drop shadow at the specified coords using the colors and the distance offset specified. It looks great!!! function blurRect(&$image, $distance, $rectX1, $rectY1, $rectX2, $rectY2, $shadowR, $shadowG, $shadowB, $backR, $backG, $backB) { $potentialOverlap = ($distance * 2) * ($distance * 2); $backgroundColor = imagecolorallocate($image, $backR, $backG, $backB); $shadowColor = imagecolorallocate($image, $shadowR, $shadowG, $shadowB); $imageWidth = imagesx($image); $imageHeight = imagesy($image); imageFilledRectangle($image, 0, 0, $imageWidth - 1, $imageHeight - 1, $backgroundColor); imageFilledRectangle($image, $rectX1, $rectY1, $rectX2, $rectY2, $shadowColor); for ( $pointX = $rectX1 - $distance; $pointX < $imageWidth; $pointX++ ) { for ( $pointY = $rectY1 - $distance; $pointY < $imageHeight; $pointY++ ) { if ( $pointX > $rectX1 + $distance && $pointX < $rectX2 - $distance && $pointY > $rectY1 + $distance && $pointY < $rectY2 - $distance ) { $pointY = $rectY2 - $distance; } $boxX1 = $pointX - $distance; $boxY1 = $pointY - $distance; $boxX2 = $pointX + $distance; $boxY2 = $pointY + $distance; $xOverlap = max(0, min($boxX2, $rectX2) - max($boxX1, $rectX1)); $yOverlap = max(0, min($boxY2, $rectY2) - max($boxY1, $rectY1)); $totalOverlap = $xOverlap * $yOverlap; $shadowPcnt = $totalOverlap / $potentialOverlap; $backPcnt = 1.0 - $shadowPcnt; $newR = $shadowR * $shadowPcnt + $backR * $backPcnt; $newG = $shadowG * $shadowPcnt + $backG * $backPcnt; $newB = $shadowB * $shadowPcnt + $backB * $backPcnt; $newcol = imagecolorallocate($image, $newR, $newG, $newB); imagesetpixel($image, $pointX, $pointY, $newcol); } } } ---- Server IP: 66.163.161.117 Probable Submitter: 129.42.208.182 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.imageconvolution.php Edit -- http://master.php.net/note/edit/63377 Del: integrated -- http://master.php.net/note/delete/63377/integrated Del: useless -- http://master.php.net/note/delete/63377/useless Del: bad code -- http://master.php.net/note/delete/63377/bad+code Del: spam -- http://master.php.net/note/delete/63377/spam Del: non-english -- http://master.php.net/note/delete/63377/non-english Del: in docs -- http://master.php.net/note/delete/63377/in+docs Del: other reasons-- http://master.php.net/note/delete/63377 Reject -- http://master.php.net/note/reject/63377 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106164) next »