note 50725 added to function.imagefilledarc
| From: | t_therkelsen at hotmail dot com | Date: | Tue, 08 Mar 2005 09:21:53 +0000 |
| Subject: | note 50725 added to function.imagefilledarc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86093@lists.php.net to get a copy of this message | ||
Note that imageFilledArc() and imageArc() both take ints as degree measurements. This is no problem
if you're *only* using imageArc() and/or imageFilledArc(). However, if you're using
calculated degrees and plan to superimpose other drawing elements (eg., you want to make vertical
lines between the shadow 3D effect) you need to floor() your degrees before converting them to
radians, otherwise you'll get precision errors.
A small example illustrating the 'feature'...
<?php
$img = imageCreate(400, 400);
$back = imageColorAllocate($img, 0, 0, 0);
$front = imageColorAllocate($img, 255, 255, 255);
$sd = 45.5;
$ed = 130.5;
imageFilledArc($img, 200, 200, 300, 300, $sd, $ed,
$front, IMG_ARC_PIE|IMG_ARC_NOFILL|IMG_ARC_EDGED);
imageArc($img, 200, 230, 300, 300, $sd, $ed, $front);
imageLine($img,
cos(deg2rad($sd))*150+200, sin(deg2rad($sd))*150+200,
cos(deg2rad($sd))*150+200, sin(deg2rad($sd))*150+230,
$front);
imageLine($img,
cos(deg2rad($ed))*150+200, sin(deg2rad($ed))*150+200,
cos(deg2rad($ed))*150+200, sin(deg2rad($ed))*150+230,
$front);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
And this is how it should be...
<?php
$img = imageCreate(400, 400);
$back = imageColorAllocate($img, 0, 0, 0);
$front = imageColorAllocate($img, 255, 255, 255);
$sd = floor(45.5);
$ed = floor(130.5);
imageFilledArc($img, 200, 200, 300, 300, $sd, $ed,
$front, IMG_ARC_PIE|IMG_ARC_NOFILL|IMG_ARC_EDGED);
imageArc($img, 200, 230, 300, 300, $sd, $ed, $front);
imageLine($img,
cos(deg2rad($sd))*150+200, sin(deg2rad($sd))*150+200,
cos(deg2rad($sd))*150+200, sin(deg2rad($sd))*150+230,
$front);
imageLine($img,
cos(deg2rad($ed))*150+200, sin(deg2rad($ed))*150+200,
cos(deg2rad($ed))*150+200, sin(deg2rad($ed))*150+230,
$front);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagefilledarc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50725
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50725&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50725&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50725&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50725&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50725&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50725&report=yes
Search -- http://master.php.net/manage/user-notes.php