note 33093 deleted from function.imageline by didou

From: Date: Mon, 16 Jun 2003 15:53:50 +0000
Subject: note 33093 deleted from function.imageline by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-50433@lists.php.net to get a copy of this message
Note Submitter: nanobot@chipx86.com ---- Here's a function to create an antialiased line: function imagesmoothline ( $image , $x1 , $y1 , $x2 , $y2 , $color ) { $colors = imagecolorsforindex ( $image , $color ); $m = ( $y2 - $y1 ) / ( $x2 - $x1 ); $b = $y1 - $m * $x1; if ( abs ( $m ) <= .5 ) { $x = min ( $x1 , $x2 ); $endx = max ( $x1 , $x2 ); while ( $x <= $endx ) { $y = $m * $x + $b; $y == floor ( $y ) ? $ya = 1 : $ya = $y - floor ( $y ); $yb = ceil ( $y ) - $y; $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , floor ( $y ) ) ); $tempcolors['red'] = $tempcolors['red'] * $ya + $colors['red'] * $yb; $tempcolors['green'] = $tempcolors['green'] * $ya + $colors['green'] * $yb; $tempcolors['blue'] = $tempcolors['blue'] * $ya + $colors['blue'] * $yb; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , $x , floor ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , ceil ( $y ) ) ); $tempcolors['red'] = $tempcolors['red'] * $yb + $colors['red'] * $ya; $tempcolors['green'] = $tempcolors['green'] * $yb + $colors['green'] * $ya; $tempcolors['blue'] = $tempcolors['blue'] * $yb + $colors['blue'] * $ya; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , $x , ceil ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $x ++; } } else { $y = min ( $y1 , $y2 ); $endy = max ( $y1 , $y2 ); while ( $y <= $endy ) { $x = ( $y - $b ) / $m; $x == floor ( $x ) ? $xa = 1 : $xa = $x - floor ( $x ); $xb = ceil ( $x ) - $x; $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , floor ( $x ) , $y ) ); $tempcolors['red'] = $tempcolors['red'] * $xa + $colors['red'] * $xb; $tempcolors['green'] = $tempcolors['green'] * $xa + $colors['green'] * $xb; $tempcolors['blue'] = $tempcolors['blue'] * $xa + $colors['blue'] * $xb; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , floor ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , ceil ( $x ) , $y ) ); $tempcolors['red'] = $tempcolors['red'] * $xb + $colors['red'] * $xa; $tempcolors['green'] = $tempcolors['green'] * $xb + $colors['green'] * $xa; $tempcolors['blue'] = $tempcolors['blue'] * $xb + $colors['blue'] * $xa; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , ceil ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $y ++; } } }

« previous php.notes (#50433) next »