note 93726 modified in function.imagesetthickness by danbrown
| From: | danbrown@php.net | Date: | Thu, 24 Sep 2009 17:39:26 +0000 |
| Subject: | note 93726 modified in function.imagesetthickness by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161027@lists.php.net to get a copy of this message | ||
While recently "playing" with GD library for PHP I also encountered the problem of
imagesetthickness not working with imageellipse.
I think I found a good work around and wanted to share it with you:
Instead of using
<?php imageellipse($image, $pos_x, $pos_y, $elipse_w, $elipse_h, $color); ?>
I successfully used:
<?php imagearc($image, $pos_x, $pos_y, $elipse_w, $elipse_h, 0, 359.9, $color); ?>
NOTE: Don't put exactly 360 instead of 359.9 because it seems that the implementation makes the
test and uses imageellipse instead!
Below is my Ellipse function that is sensitive to imagesetthickness function AND that creates a
properly closed ellipse.
<?php
function myimageellipse($image, $x, $y, $rx, $ry, $color)
{
// We don't use imageellipse because the imagesetthickness function has
// no effect. So the better workaround is to use imagearc.
imagearc($image,$x,$y,$rx,$ry, 0,359,$color);
// If we stop here, we don't have a properly closed ellipse.
// Using imagefill at this point will flood outside the ellipse (actually arc).
// We have to close the arc to make it a real ellipse.
$cos359=0.99984769;
$sin359=-0.01745240;
$x1=round($x+$rx/2*$cos359);
$y1=round($y+$ry/2*$sin359);
$x2=round($x+$rx/2);
$y2=round($y);
// imageline is sensitive to imagesetthickness as well.
imageline($image,$x1,$y1,$x2,$y2,$color);
}
?>
--was--
Sorry, in my previous post I didn't consider to fill color inside the badly closed ellipse.
Below is my Ellipse function that is sensitive to imagesetthickness function AND that creates a
properly closed ellipse.
function myimageellipse($image, $x, $y, $rx, $ry, $color)
{
// We don't use imageellipse because the imagesetthickness function has
// no effect. So the better workaround is to use imagearc.
imagearc($image,$x,$y,$rx,$ry, 0,359,$color);
// If we stop here, we don't have a properly closed ellipse.
// Using imagefill at this point will flood outside the ellipse (actually arc).
// We have to close the arc to make it a real ellipse.
$cos359=0.99984769;
$sin359=-0.01745240;
$x1=round($x+$rx/2*$cos359);
$y1=round($y+$ry/2*$sin359);
$x2=round($x+$rx/2);
$y2=round($y);
// imageline is sensitive to imagesetthickness as well.
imageline($image,$x1,$y1,$x2,$y2,$color);
}
http://php.net/manual/en/function.imagesetthickness.php