note 64115 added to function.imagecopymerge

From: Date: Fri, 07 Apr 2006 19:03:56 +0000
Subject: note 64115 added to function.imagecopymerge
Groups: php.notes 
Request: Send a blank email to php-notes+get-107536@lists.php.net to get a copy of this message
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]) ); } } } ---- Server IP: 216.194.113.175 Probable Submitter: 128.32.142.142 ---- 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.imagecopymerge.php Edit -- http://master.php.net/note/edit/64115 Del: integrated -- http://master.php.net/note/delete/64115/integrated Del: useless -- http://master.php.net/note/delete/64115/useless Del: bad code -- http://master.php.net/note/delete/64115/bad+code Del: spam -- http://master.php.net/note/delete/64115/spam Del: non-english -- http://master.php.net/note/delete/64115/non-english Del: in docs -- http://master.php.net/note/delete/64115/in+docs Del: other reasons-- http://master.php.net/note/delete/64115 Reject -- http://master.php.net/note/reject/64115 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107536) next »