The php Function ImagefilledRectangle
PHP makes it easy to draw shapes such as squares, rectangles, circles, ellipses and polygons with its GD Library functions. These functions require certain parameters, first identifying the image to draw on and then specifying the position, size or color of the object being drawn.
This article discusses the php function imagefilledrectangle, which draws a filled rectangle in an image with rounded corners. This is an excellent example of how to use GD image manipulation functions.
To get started, we open an image using the GD Image function imagecreatetruecolor(). We then create a resource representing this image, and assign it to a variable called $image. Next, we allocate a color to be used in the image with the imagecolorallocate() function, and then we draw a rectangle with the imagefilledrectangle() function.
We start the rectangle with the upper left coordinates x1 and y1, and then we move it to the bottom right coordinates x2 and y2. We do this by calling imagefilledrectangle() each time we move the rectangle, making it smaller each time. The imagefilledrectangle() function also draws the text "Hello, World!" to the top of the image with a font file and size that we specify.
The imagefilledrectangle() function returns TRUE if it succeeds, and FALSE if it fails to do so. It is important to note that you must order the x and y coordinates in the image in the same way as you used them when creating the image with the imagecreatetruecolor() function.