imagesetstyle

(PHP 4 >= 4.0.6, PHP 5)

imagesetstyle -- 線描画用のスタイルを設定する

説明

bool imagesetstyle ( resource image, array style )

imagesetstyle() は、特別な IMG_COLOR_STYLED または色を有するイメージの線 IMG_COLOR_STYLEDBRUSHED を描画する際に (imageline()imagepolygon() のような) 全ての線描画関数で使用されるスタイルを設定します。

パラメータ

image

imagecreatetruecolor() のような画像作成関数が返す画像リソース。

style

はピクセルの配列です。定数 IMG_COLOR_TRANSPARENT を使用すると、透明なピクセルを追加できます。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

以下の例は、キャンバスの左上から右下隅に破線を描画するスクリプトです。

例 1. imagesetstyle() の例

<?php
header
("Content-type: image/jpeg");
$im  = imagecreatetruecolor(100, 100);
$w   = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* 5 ピクセルの赤線と 5 ピクセルの白線の破線を描画します */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

/* imagesetstyle を併用した imagesetbrush() を使用して happy face の線を描画します */
$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);
?>

上の例の出力は、たとえば 以下のようになります。

参考

imagesetbrush()
imageline()