note 61932 added to function.imageantialias

From: Date: Wed, 15 Feb 2006 13:22:45 +0000
Subject: note 61932 added to function.imageantialias
Groups: php.notes 
Request: Send a blank email to php-notes+get-103769@lists.php.net to get a copy of this message
Here is an optimized version of the optimized version of the antialiased circle function by sebbi: (more than 20 times faster)... <?php function imageSmoothCircle( &$img, $cx, $cy, $cr, $color ) { $ir = $cr; $ix = 0; $iy = $ir; $ig = 2 * $ir - 3; $idgr = -6; $idgd = 4 * $ir - 10; $fill = imageColorExactAlpha( $img, $color[ 'R' ], $color[ 'G' ], $color[ 'B' ], 0 ); imageLine( $img, $cx + $cr - 1, $cy, $cx, $cy, $fill ); imageLine( $img, $cx - $cr + 1, $cy, $cx - 1, $cy, $fill ); imageLine( $img, $cx, $cy + $cr - 1, $cx, $cy + 1, $fill ); imageLine( $img, $cx, $cy - $cr + 1, $cx, $cy - 1, $fill ); $draw = imageColorExactAlpha( $img, $color[ 'R' ], $color[ 'G' ], $color[ 'B' ], 42 ); imageSetPixel( $img, $cx + $cr, $cy, $draw ); imageSetPixel( $img, $cx - $cr, $cy, $draw ); imageSetPixel( $img, $cx, $cy + $cr, $draw ); imageSetPixel( $img, $cx, $cy - $cr, $draw ); while ( $ix <= $iy - 2 ) { if ( $ig < 0 ) { $ig += $idgd; $idgd -= 8; $iy--; } else { $ig += $idgr; $idgd -= 4; } $idgr -= 4; $ix++; imageLine( $img, $cx + $ix, $cy + $iy - 1, $cx + $ix, $cy + $ix, $fill ); imageLine( $img, $cx + $ix, $cy - $iy + 1, $cx + $ix, $cy - $ix, $fill ); imageLine( $img, $cx - $ix, $cy + $iy - 1, $cx - $ix, $cy + $ix, $fill ); imageLine( $img, $cx - $ix, $cy - $iy + 1, $cx - $ix, $cy - $ix, $fill ); imageLine( $img, $cx + $iy - 1, $cy + $ix, $cx + $ix, $cy + $ix, $fill ); imageLine( $img, $cx + $iy - 1, $cy - $ix, $cx + $ix, $cy - $ix, $fill ); imageLine( $img, $cx - $iy + 1, $cy + $ix, $cx - $ix, $cy + $ix, $fill ); imageLine( $img, $cx - $iy + 1, $cy - $ix, $cx - $ix, $cy - $ix, $fill ); $filled = 0; for ( $xx = $ix - 0.45; $xx < $ix + 0.5; $xx += 0.2 ) { for ( $yy = $iy - 0.45; $yy < $iy + 0.5; $yy += 0.2 ) { if ( sqrt( pow( $xx, 2 ) + pow( $yy, 2 ) ) < $cr ) $filled += 4; } } $draw = imageColorExactAlpha( $img, $color[ 'R' ], $color[ 'G' ], $color[ 'B' ], ( 100 - $filled ) ); imageSetPixel( $img, $cx + $ix, $cy + $iy, $draw ); imageSetPixel( $img, $cx + $ix, $cy - $iy, $draw ); imageSetPixel( $img, $cx - $ix, $cy + $iy, $draw ); imageSetPixel( $img, $cx - $ix, $cy - $iy, $draw ); imageSetPixel( $img, $cx + $iy, $cy + $ix, $draw ); imageSetPixel( $img, $cx + $iy, $cy - $ix, $draw ); imageSetPixel( $img, $cx - $iy, $cy + $ix, $draw ); imageSetPixel( $img, $cx - $iy, $cy - $ix, $draw ); } } $img = imageCreateTrueColor( 320, 240 ); imageSmoothCircle( $img, 160, 120, 100, array( 'R' => 0xCC, 'G' => 0x33, 'B' => 0x00 ) ); imageSmoothCircle( $img, 170, 110, 75, array( 'R' => 0xDD, 'G' => 0x66, 'B' => 0x00 ) ); imageSmoothCircle( $img, 180, 100, 50, array( 'R' => 0xEE, 'G' => 0x99, 'B' => 0x00 ) ); imageSmoothCircle( $img, 190, 90, 25, array( 'R' => 0xFF, 'G' => 0xCC, 'B' => 0x00 ) ); header( 'Content-Type: image/png' ); imagePNG( $img ); ?> ---- Server IP: 217.13.201.10 Probable Submitter: 84.141.35.90 ---- Manual Page -- http://www.php.net/manual/en/function.imageantialias.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61932 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61932&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61932&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103769) next »