imagerectangle

(PHP 4, PHP 5, PHP 7, PHP 8)

imagerectangle绘制矩形

说明

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

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

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

x1

左上角 x 坐标。

y1

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

x2

右下角 x 坐标。

y2

右下角 y 坐标。

color

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

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 image 现在需要 GdImage 实例;之前需要有效的 gd resource

范例

示例 #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);
?>

以上例程的输出类似于:

示例输出:imagerectangle() 的简单示例

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top