note 64115 deleted from function.imagecopymerge by bjori

From: Date: Fri, 27 Oct 2006 10:27:05 +0000
Subject: note 64115 deleted from function.imagecopymerge by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119176@lists.php.net to get a copy of this message
Note Submitter: bram at bldesign dot org ---- I was trying to write a function to watermark images, but the results weren't great, so I decided to write my own dodge and burn functions. Dodging brightens the destination image according to the source image, burning darkens. Dodging with black or burning with white do nothing, so those can basically be used as transparency. In both cases, the function will copy the entire $src image to $dst at location $dstx, $dsty with intensity $pct. $src and $dst should be handles to true color images. function imagecopydodge($dst,$src,$dstx,$dsty,$pct) { $w = imagesx($src); $h = imagesy($src); $i = 0; $j = 0; $k = 0; $rgb = 0; $d = array(); $s = array(); for ($i=0; $i<$h; $i++) { for ($j=0; $j<$w; $j++) { $rgb = imagecolorat($dst,$dstx+$j,$dsty+$i); $d[0] = ($rgb >> 16) & 0xFF; $d[1] = ($rgb >> 8) & 0xFF; $d[2] = $rgb & 0xFF; $rgb = imagecolorat($src,$j,$i); $s[0] = ($rgb >> 16) & 0xFF; $s[1] = ($rgb >> 8) & 0xFF; $s[2] = $rgb & 0xFF; $d[0] += min($s[0],0xFF-$d[0])*$pct/100; $d[1] += min($s[1],0xFF-$d[1])*$pct/100; $d[2] += min($s[2],0xFF-$d[2])*$pct/100; imagesetpixel( $dst, $dstx+$j, $dsty+$i, imagecolorallocate($dst,$d[0],$d[1],$d[2]) ); } } } function imagecopyburn($dst,$src,$dstx,$dsty,$pct) { $w = imagesx($src); $h = imagesy($src); $i = 0; $j = 0; $k = 0; $rgb = 0; $d = array(); $s = array(); for ($i=0; $i<$h; $i++) { for ($j=0; $j<$w; $j++) { $rgb = imagecolorat($dst,$dstx+$j,$dsty+$i); $d[0] = ($rgb >> 16) & 0xFF; $d[1] = ($rgb >> 8) & 0xFF; $d[2] = $rgb & 0xFF; $rgb = imagecolorat($src,$j,$i); $s[0] = ($rgb >> 16) & 0xFF; $s[1] = ($rgb >> 8) & 0xFF; $s[2] = $rgb & 0xFF; $d[0] -= max($d[0]-$s[0],0)*$pct/100; $d[1] -= max($d[1]-$s[1],0)*$pct/100; $d[2] -= max($d[2]-$s[2],0)*$pct/100; imagesetpixel( $dst, $dstx+$j, $dsty+$i, imagecolorallocate($dst,$d[0],$d[1],$d[2]) ); } } }

« previous php.notes (#119176) next »