array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.imagerectangle.php', 1 => 'imagerectangle', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD および Image 関数', ), 'prev' => array ( 0 => 'function.imagepolygon.php', 1 => 'imagepolygon', ), 'next' => array ( 0 => 'function.imageresolution.php', 1 => 'imageresolution', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/image/functions/imagerectangle.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagerectangle — 矩形を描画する
imagerectangle() は、指定した座標から始まる矩形を作成します。
image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
x1
左上の x 座標。
y1
左上の y 座標。 0, 0 が画像の左上隅を表します。
x2
右下の x 座標。
y2
右下の y 座標。
color
imagecolorallocate() で作成された色識別子。
バージョン | 説明 |
---|---|
8.0.0 |
image は、
GdImage
クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、有効な gd resource が期待されていました。
|
例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);
?>
上の例の出力は、 たとえば以下のようになります。