imagerectangle
(PHP 4, PHP 5)
imagerectangle — 矩形を描画する
説明
bool imagerectangle
( resource
$image
, int $x1
, int $y1
, int $x2
, int $y2
, int $color
)imagerectangle() は、指定した座標から始まる矩形を作成します。
パラメータ
-
image -
imagecreatetruecolor() のような画像作成関数が返す画像リソース。
-
x1 -
左上の x 座標。
-
y1 -
左上の y 座標。 0, 0 が画像の左上隅を表します。
-
x2 -
右下の x 座標。
-
y2 -
右下の y 座標。
-
color -
imagecolorallocate() で作成した色 ID。
返り値
成功した場合に 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);
?>
上の例の出力は、 たとえば以下のようになります。