Here is a custom function I wrote that addresses the line thickness issues with ellipses :
function draw_oval ($image, $pos_x, $pos_y, $elipse_width, $elipse_height, $color, $px_thick) {
$line = 0;
$thickness = $px_thick;
$elipse_w = $elipse_width;
$elipse_h = $elipse_height;
while ($line < $thickness) {
imageellipse($image, $pos_x, $pos_y, $elipse_w, $elipse_h, $color);
$line++;
$elipse_w--;
$elipse_h--;
}
}
I hope you find this useful.
imagesetthickness
(PHP 4 >= 4.0.6, PHP 5)
imagesetthickness — 線描画用の線幅を設定する
説明
bool imagesetthickness
( resource $image
, int $thickness
)
imagesetthickness() は、長方形、多角形、楕円等を描画する際の線幅を thickness ピクセルに設定します。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例1 imagesetthickness() の例
<?php
// 200x100 の画像を作成します
$im = imagecreatetruecolor(200, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
// 背景を白に設定します
imagefilledrectangle($im, 0, 0, 299, 99, $white);
// 線幅を 5 に設定します
imagesetthickness($im, 5);
// 矩形を描画します
imagerectangle($im, 14, 14, 185, 85, $black);
// 画像をブラウザに出力します
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
上の例の出力は、たとえば 以下のようになります。
注意
注意: この関数は、GD 2.0.1 以降を必要とします (2.0.28 以降を推奨します)。
imagesetthickness
admin at circle14 dot net
02-Feb-2009 03:33
02-Feb-2009 03:33
bpatru at gmail dot com
28-Sep-2008 11:01
28-Sep-2008 11:01
Apparently imagesetthickness doesn't work if antialiasing is set to true.
baldurien at bbnwn dot eu
12-Mar-2008 02:28
12-Mar-2008 02:28
The way that imagesetthickness works with imagerectangle() is pretty strange.
<?php
imagesetthickness(1);
imagerectangle($im, 10, 10, 50, 50, $red);
?>
This will draw a 41x41 square (because gd need the bottom right pixel, inclusive. 50 should get replaced by 49). This will "work" like:
<?php
imageline($im, 10, 10, 10, 50, $red);
imageline($im, 10, 10, 50, 10, $red);
imageline($im, 50, 10, 50, 50, $red);
imageline($im, 10, 50, 50, 50, $red);
?>
The second example:
<?php
imagesetthickness(2);
imagerectangle($im, 10, 10, 50, 50, $red);
?>
This will draw a 43x43 square because the border (thickness) is set to 2. *however* this is not a "regular" border of 2 pixels around the 41x41 original square!
On the left and right, there will be a thickness of 3, while there we be a thickness of 2.
If you take the imageline example, but set the thickness before to 2, this will *almost* do the trick: the left most pixel of the square will not be drawn.
To conclude:
1) do not forget that (width, height) of drawn rectangle is (x2-x1+1, y2-y1+1)
2) thickness is bad implemented (or at least, the behavior i s not documented) on rectangle, as the left/right thickness is not the wanted one.
3) 4*imageline() should do the trick, but after "patching" the top left pixel.
ab at cd dot com
27-Jun-2007 02:05
27-Jun-2007 02:05
Note: Also, for me (working under PHP 5.0.2) this function ONLY seems to work with imageline...
