(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagesetstyle — 線描画用のスタイルを設定する
imagesetstyle() は、特別な IMG_COLOR_STYLED
または色を有するイメージの線 IMG_COLOR_STYLEDBRUSHED
を描画する際に (imageline() と imagepolygon() のような) 全ての線描画関数で使用されるスタイルを設定します。
image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
style
はピクセルの配列です。定数 IMG_COLOR_TRANSPARENT
を使用すると、透明なピクセルを追加できます。 style
は空の配列にしてはいけません。
以下の例は、キャンバスの左上から右下隅に破線を描画するスクリプトです。
例1 imagesetstyle() の例
<?php
header("Content-type: image/jpeg");
$im = imagecreatetruecolor(100, 100);
$w = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);
$brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($im, $brush);
imageline($im, 100, 0, 0, 100, IMG_COLOR_STYLEDBRUSHED);
imagejpeg($im);
imagedestroy($im);
?>
上の例の出力は、 たとえば以下のようになります。