首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

imagerectangle

(PHP 4, PHP 5, PHP 7)

imagerectangle - 绘制一个矩形

描述

代码语言:javascript
复制
bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )

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

参数

代码语言:txt
复制
`image`   

一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。

x1

左上角的x坐标。

y1

左上方y坐标0,0是图像的左上角。

x2

底部右侧x坐标。

y2

右下角y坐标。

color

使用imagecolorallocate()创建的颜色标识符。

返回值

返回TRUE成功或失败时返回FALSE

例子

Example #1 Simple imagerectangle() example

代码语言:javascript
复制
<?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);
?>

上面的例子会输出类似于:

← imagepstext

imageresolution →

扫码关注腾讯云开发者

领取腾讯云代金券