imagefilledrectangle
(PHP 4, PHP 5, PHP 7, PHP 8)
imagefilledrectangle — Draw a filled rectangle
Description
Creates a rectangle filled with color in the given image starting at point 1 and ending at point 2. 0, 0 is the top left corner of the image.
Parameters
imageA GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
x1x-coordinate for point 1.
y1y-coordinate for point 1.
x2x-coordinate for point 2.
y2y-coordinate for point 2.
colorThe fill 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 imagefilledrectangle() usage
<?php
// Create a 55x30 image
$im = imagecreatetruecolor(55, 30);
$white = imagecolorallocate($im, 255, 255, 255);
// Draw a white rectangle
imagefilledrectangle($im, 4, 4, 50, 25, $white);
// Save the image
imagepng($im, './imagefilledrectangle.png');
?>The above example will output something similar to:
↑ and ↓ to navigate • Enter to select • Esc to close • / to open