Use a brush to create a thick line.
To create a 3x3 red brush:
<?php
$brush_size = 3;
$brush = imagecreatetruecolor($brush_size,$brush_size);
$brush_color = imagecolorallocate($brush,255,0,0);
imagefill($brush,0,0,$brush_color);
imagesetbrush($im,$brush);
?>
Then use imageline() or imagepolygon() with IMG_COLOR_BRUSHED as the color.
To stop using the brush, destroy it:
<?php imagedestroy($brush); ?>
The brush can also be created from an existing image.
imagesetbrush
(PHP 5 >= 5.5.0)
imagesetbrush — 線の描画用にブラシイメージを設定する
説明
bool imagesetbrush
( resource
$image
, resource $brush
)
imagesetbrush() は、特別な色
IMG_COLOR_BRUSHED または
IMG_COLOR_STYLEDBRUSHED で描画される際に
( imageline() や
imagepolygon() のような)
全ての線描画関数で使用されるブラシイメージを設定します。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例1 imagesetbrush() の例
<?php
// 小さい php ロゴを読み込みます
$php = imagecreatefrompng('./php.png');
// 100x100 のメイン画像を作成します
$im = imagecreatetruecolor(100, 100);
// 背景を白で塗りつぶします
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 299, 99, $white);
// ブラシを設定します
imagesetbrush($im, $php);
// いくつかのブラシを重ねます
imageline($im, 50, 50, 50, 60, IMG_COLOR_BRUSHED);
// 画像をブラウザに出力します
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
imagedestroy($php);
?>
上の例の出力は、 たとえば以下のようになります。
注意
注意:
ブラシの使用が終った際には特別な処理は不要ですが、 ブラシイメージを破棄する場合には、新たにブラシイメージを設定するまでは、 色
IMG_COLOR_BRUSHEDまたはIMG_COLOR_STYLEDBRUSHEDを使用するべきではありません。
brent at ebrent dot net ¶
6 years ago
