Draw a rectangle

# imagerectangle

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

imagerectangle — Draw a rectangle

### Description

function imagerectangle(
GdImage `$image`,
int `$x1`,
int `$y1`,
int `$x2`,
int `$y2`,
int `$color`
): true

imagerectangle() creates a rectangle starting at the specified coordinates. 0, 0 is the top left corner of the image.

### Parameters

`image`
  A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
`x1`

  Upper left x coordinate.

`y1`

  Upper left y coordinate.

`x2`

  Bottom right x coordinate.

`y2`

  Bottom right y coordinate.

`color`

  A color identifier created with imagecolorallocate().

### Return Values

Always returns `true`.

### Changelog

Version | Description
--- | ---
8.0.0 | `image` expects a GdImage instance now; previously, a valid `gd` resource was expected.

### Examples

Example #1 Simple imagerectangle() example

    <?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
    header('Content-Type: image/jpeg');
    imagejpeg($canvas);
    ?>

The above example will output something similar to:

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open