note 106939 deleted from function.imageantialias by danbrown

From: Date: Tue, 03 Jan 2012 22:07:17 +0000
Subject: note 106939 deleted from function.imageantialias by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185322@lists.php.net to get a copy of this message
Note Submitter: rudolf.malutki[x]gmail.com ---- I little change function for transparent background. function imagecircleaa($img, $cx, $cy, $r, $w, $s, $t, $color) // image, centerX, centerY, radius, stroke width, aa width, tightness, color { $adj = $w + $s; $sCol = imagecolorallocate($img, $color['r'], $color['g'], $color['b']); for($x = -$r - $adj; $x <= $r + $adj; $x++) { for($y = -$r - $adj; $y <= $r + $adj; $y++) { $d = sqrt($x * $x + $y * $y); // distance from pixel to center $err = abs($d - $r); // absolute distance from pixel to circle edge if($err <= $w / 2 + $s) // within the stroke width + smoothing radius { if($err <= $w / 2) // inside the stroke width so make it solid color { $aaCol = $sCol; } else // in the antialisaing region so make it a blended color { $err -= $w / 2; // adjust to the aliased part $err = 1 - $err / $s; // adjust to between 0 and 1 $err = ($err - 0.5) * $t * 2; // adjust to -$t to +$t for tightness $err = ($err / sqrt(1 + $err * $err) + 1) / 2; // sigmoid curve to smooth edges $aaCol = imagecolorallocatealpha($img,$color['r'], $color['g'], $color['b'],127-(127*$err)); } imagesetpixel($img, $x + $cx, $y + $cy, $aaCol); } } } }

« previous php.notes (#185322) next »