note 102762 modified in function.imagearc by danbrown

From: Date: Fri, 04 Mar 2011 14:50:45 +0000
Subject: note 102762 modified in function.imagearc by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177560@lists.php.net to get a copy of this message
Hi, this is a function that replaces "imagearc" to solve the thickness-problem. it does not use the global value set by imagesetthickness, so you have to pass it along. "connecting" the arc to lines is still a problem, it sometimes shifts by 1px, but so does the original function. Theres still alot to improve ... <?php function myimagearc($im,$mid_x,$mid_y,$rad,$w1,$w2,$col,$thickness){ global $cols; $rad+=$thickness/2; // to calculate outer edge $th_fact = 1-((($thickness-1)/$rad)); $pts = 36*$rad; // adjust density $fact = $pts/360; $w1 = $w1*$fact; $w2 = $w2*$fact; if($thickness > 2) // to make sure we have neither gaps nor ugly looking artefacts imagesetthickness($handle,2); else imagesetthickness($handle,1); $winkel = (2*pi())/$pts; for($i=$w1+1;$i< $w2;$i++){ $x = (cos($i*$winkel)*($rad)); $y = (sin($i*$winkel)*($rad)); $x1 = $x+$mid_x; $y1 = $y+$mid_y; $x2 = $th_fact*$x+$mid_x; $y2 = $th_fact*$y+$mid_y; imageline($im, $x1,$y1,$x2,$y2,$col); } imagesetthickness($handle,1); // just to reset } ?> --was-- Hi, this is a function that replaces "imagearc" to solve the thickness-problem. it does not use the global value set by imagesetthickness, so you have to pass it along. "connecting" the arc to lines is still a problem, it sometimes shifts by 1px, but so does the original function. Theres still alot to improve ... function myimagearc($im,$mid_x,$mid_y,$rad,$w1,$w2,$col,$thickness){ global $cols; $rad+=$thickness/2; // to calculate outer edge $th_fact = 1-((($thickness-1)/$rad)); $pts = 36*$rad; // adjust density $fact = $pts/360; $w1 = $w1*$fact; $w2 = $w2*$fact; if($thickness > 2) // to make sure we have neither gaps nor ugly looking artefacts imagesetthickness($handle,2); else imagesetthickness($handle,1); $winkel = (2*pi())/$pts; for($i=$w1+1;$i< $w2;$i++){ $x = (cos($i*$winkel)*($rad)); $y = (sin($i*$winkel)*($rad)); $x1 = $x+$mid_x; $y1 = $y+$mid_y; $x2 = $th_fact*$x+$mid_x; $y2 = $th_fact*$y+$mid_y; imageline($im, $x1,$y1,$x2,$y2,$col); } imagesetthickness($handle,1); // just to reset } http://php.net/manual/en/function.imagearc.php

« previous php.notes (#177560) next »