The bug reported by 'michi at marel dot at' also exists in PHP version 5.1.1. This functions just works with vertical lines!
imagedashedline
(PHP 4, PHP 5)
imagedashedline — 破線を描画する
説明
bool imagedashedline
( resource $image
, int $x1
, int $y1
, int $x2
, int $y2
, int $color
)
これは古い関数です。代わりに imagesetstyle() と imageline() の組み合せを使用してください。
パラメータ
- image
-
imagecreatetruecolor() のような画像作成関数が返す画像リソース。
- x1
-
左上の x 座標。
- y1
-
左上の y 座標 0。0 は画像の左上の角です。
- x2
-
右下の x 座標。
- y2
-
右下の y 座標。
- color
-
塗りつぶし色。 imagecolorallocate() で作成した色 ID。
返り値
常に true を返します。
例
例1 imagedashedline() の例
<?php
// 100x100 の画像を作成します
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// 縦の破線を描画します
imagedashedline($im, 50, 25, 50, 75, $white);
// 画像を保存します
imagepng($im, './dashedline.png');
imagedestroy($im);
?>
上の例の出力は、 たとえば以下のようになります。
例2 imagedashedline() のもうひとつの使用法
<?php
// 100x100 の画像を作成します
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// 独自のスタイルの作成: 最初の 4 ピクセルを白色、
// 次の 4 ピクセルを透明とし、破線風の効果を作成します
$style = Array(
$white,
$white,
$white,
$white,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT
);
imagesetstyle($im, $style);
// 破線を描画します
imageline($im, 50, 25, 50, 75, IMG_COLOR_STYLED);
// 画像を保存します
imagepng($im, './imageline.png');
imagedestroy($im);
?>
imagedashedline
ProfessorNeo at gmx dot de
16-Feb-2006 08:07
16-Feb-2006 08:07
alien-scripts.de
13-Jul-2005 09:17
13-Jul-2005 09:17
I make my own dashedline:
<?
for($l=50;$l<=550;$l+=5)
{
if($da == 0) { $da = 1; }
elseif($da == 1){
imageline($bild,$l,50,$l+5,50,$green);
$da = 0; }
}
?>
$l is the x-value
and we have a dashed line :)
michi at marel dot at
19-Nov-2003 02:49
19-Nov-2003 02:49
There's a bug till PHP 4.0.4 in this function. You can only draw vertical dashed lines. To draw other dashed lines you can set <ImageSetStyle> to a special dashed line and draw it by <ImageLine>.
Sample code:
<?php
function MDashedLine($image, $x0, $y0, $x1, $y1, $fg, $bg)
{
$st = array($fg, $fg, $fg, $fg, $bg, $bg, $bg, $bg);
ImageSetStyle($image, $st);
ImageLine($image, $x0, $y0, $x1, $y1, IMG_COLOR_STYLED);
}
?>
