Php/docs/function.imagesetstyle

提供:Dev Guides
< Php
移動先:案内検索

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

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


説明

imagesetstyle ( resource $image , array $style ) : bool

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


パラメータ

image
imagecreatetruecolor() のような画像作成関数が返す画像リソース。
style
はピクセルの配列です。定数 IMG_COLOR_TRANSPARENT を使用すると、透明なピクセルを追加できます。 style は空の配列にしてはいけません。


返り値

成功した場合に true を、失敗した場合に false を返します。


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

例1 imagesetstyle() の例

<?phpheader("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%22);$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);?>

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


参考