imagerectangle()创建一个从指定坐标开始的矩形。

 

句法

PHP imagerectangle()函数具有以下语法。

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

 

参数

PHP imagerectangle()函数具有以下参数。

  • image - 由图像创建函数(如imagecreatetruecolor())返回的图像资源。
  • x1 - 左上角x坐标。
  • y1 - 左上y坐标0,0是图像的左上角。
  • x2 - 右下角x坐标。
  • y2 - 右下y坐标。
  • color - 使用imagecolorallocate()创建的颜色标识符。

 

返回值

成功时返回TRUE,失败时返回FALSE。

 

实例

<?php
/*
http://www.manongjc.com/article/1757.html
作者:码农教程
*/
// 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);
?>
收藏 打印