Page 1 of 1

ImageArc Error or Am I Missing Something?

Posted: Fri Mar 07, 2003 7:15 am
by samsonite451

Code: Select all

<?php
$im = imagecreate(500, 500);
$background = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
imagearc($im, 250, 250, 200, 100, 0, 360, $black);
imagearc($im, 250, 250, 200, 100, 0,  45, $white);
header ("Content-type: image/png");
imagepng($im);
?>
I was expecting this to create a black ellipse with a 45 degree section notched out from around 3:00 to 4:30. It didn't look quite right, so I got out my handy-dandy protractor, and it would appear that what I got was a black ellipse with only 25-30 degrees notched out. It seems to only plot correctly when the angle is either 0, 90, 180, or 270. I am using php-4.2.2-8.0.7 with httpd-2.0.40-11 and gd-1.8.4-9 on RedHat 8.0.

Posted: Fri Mar 07, 2003 11:28 am
by volka
maybe this explains it

Code: Select all

<?php
$im = imagecreate(500, 500);
$background = imagecolorallocate($im, 0xAF, 0xAF, 0xAF);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

$g1 = imagecolorallocate($im, 128, 128, 128);

for ($i=360; $i!=0; $i-=10)
   imagefilledarc($im, 250, 250, 200, 100, $i-5, $i, $g1, IMG_ARC_PIE);

imagearc($im, 250, 250, 200, 100, 0, 360, $black);
imagearc($im, 250, 250, 200, 100, 0,  45, $white);

header ("Content-type: image/png");
imagepng($im);
?>
btw: why do you let the script draw the complete arc anyway?

Code: Select all

<?php
$im = imagecreate(500, 500);
$background = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0, 0, 0);
imagearc($im, 250, 250, 200, 100, 45, 360, $black);
header ("Content-type: image/png");
imagepng($im);
?>

Posted: Fri Mar 07, 2003 9:33 pm
by samsonite451
That doesn't seem to have changed the results any. The angle still shows up as 25-30 degress.

As for the oddness of the script, it looks unusual because I took the snippet of code from a much larger script I wrote and stripped it down to only the pertinent sections. In the original script, duplication of the imagearc calls makes a little more sense because I'm adding and removing sections of the border throughout the script.

Edit: Further inspection of the source code leads me to believe that the error lies entirely in the gd source code, so I guess my next step is to see if their latest release fixes my problems. I just dislike compiling from source when there are rpm's available. It makes updates so much messier.

Posted: Sat Mar 08, 2003 2:00 am
by volka
the first example shows you how proportions work for an ellipse with gd.

Code: Select all

<?php
$im = imagecreate(500, 500);
$background = imagecolorallocate($im, 0xAF, 0xAF, 0xAF);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

$g1 = imagecolorallocate($im, 128, 128, 128);

for ($i=360; $i!=0; $i-=10)
   imagefilledarc($im, 150, 120, 200, 100, $i-5, $i, $g1, IMG_ARC_PIE);

for ($i=360; $i!=0; $i-=10)
   imagefilledarc($im, 350, 120, 100, 200, $i-5, $i, $g1, IMG_ARC_PIE);

for ($i=360; $i!=0; $i-=10)
   imagefilledarc($im, 150, 300, 200, 200, $i-5, $i, $g1, IMG_ARC_PIE);

header ("Content-type: image/png");
imagepng($im);
?>
It's like drawing a circle and then rotate it along the longer dimension's axis. sectors get smaller near this axis.
Probably all versions of gd handle it this way.

Posted: Sat Mar 08, 2003 8:27 am
by samsonite451
Thanks for your reply. I honestly hadn't tried to use your first example because it included imagefilledarc, which my version doesn't support (requires gd-2 or better). So I skipped straight to the second example and missed the point you were making with the first one. Do you happen to know why they would choose to draw ellipses that way instead of using the correct angles with respect to the center-point?