array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagerectangle.php', 1 => 'imagerectangle', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagepolygon.php', 1 => 'imagepolygon', ), 'next' => array ( 0 => 'function.imageresolution.php', 1 => 'imageresolution', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', '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() 创建。
示例 #1 imagerectangle() 的简单示例
<?php
// Create a 200 x 200 image
$canvas = imagecreatetruecolor(200, 200);
// Allocate colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);
// Draw three rectangles each with its own color
imagerectangle($canvas, 50, 50, 150, 150, $pink);
imagerectangle($canvas, 45, 60, 120, 100, $white);
imagerectangle($canvas, 100, 120, 75, 160, $green);
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($canvas);
imagedestroy($canvas);
?>
以上示例的输出类似于: