Php/docs/function.imagerectangle

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

imagerectangle

(PHP 4, PHP 5, PHP 7)

imagerectangle矩形を描画する


説明

imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) : bool

imagerectangle() は、指定した座標から始まる矩形を作成します。


パラメータ

image
imagecreatetruecolor() のような画像作成関数が返す画像リソース。
x1
左上の x 座標。
y1
左上の y 座標。 0, 0 が画像の左上隅を表します。
x2
右下の x 座標。
y2
右下の y 座標。
color
imagecolorallocate() で作成された色識別子。


返り値

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


例1 シンプルな imagerectangle() の例

<?php// 200 x 200 の画像を作成します$canvas = imagecreatetruecolor(200, 200);// 色を割り当てます$pink = imagecolorallocate($canvas, 255, 105, 180);$white = imagecolorallocate($canvas, 255, 255, 255);$green = imagecolorallocate($canvas, 132, 135, 28);// 3 つの矩形をそれぞれの色で描画しますimagerectangle($canvas, 50, 50, 150, 150, $pink);imagerectangle($canvas, 45, 60, 120, 100, $white);imagerectangle($canvas, 100, 120, 75, 160, $green);// 出力してメモリから解放しますheader('Content-Type: image/jpeg');imagejpeg($canvas);imagedestroy($canvas);?>

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