Introduction
In this article I explain how to draw basic shapes in PHP. PHP shapes are a very simple. You can easily draw in your application, but before creating a shape program you should install the GD library. The PHP GD library is very helpful for creating an image program in PHP, therefore you need to include the GD library in your PHP application. Let's begin a basic shapes drawing
program using the PHP GD library. In this article I will use some image functions.
To define an image color in GD, you need to use the "ImageCreatTrueColor[]" function. All shapes are shown in a browser as a PNG file.
Example
In this example I used a green background color and output this graphics to the browser as a .PNG file.
Output
Example
Draw a
Simple Line Shape
Output
Example
Draw a Simple Rectangle Shape
Output
Example
Draw a Simple Circle Shape
Output
How to draw rectangles in PHP?
PHP | imagefilledrectangle[] Function
The imagefilledrectangle[] function is an inbuilt function in PHP which is used to create a filled rectangle. This function creates a rectangle filled with a given color in the image. The top left corner of the image is [0, 0].
How to draw Lines in PHP?
Normally in PHP you would use the imageline[] function to draw a line between two points. The following block of code creates and image and draws a white line from the coordinates 50x,50y to 200x,150y.
...
Drawling A Line With Pixels In PHP..
Can we draw images using PHP?
PHP provides many functions to draw lines, rectangles, polygons, arcs, ellipses and much more. The GD library is utilized for dynamic picture creation. In PHP, we can easily use the GD library to make GIF, PNG, or JPG pictures quickly from our code.
How to make graphics in PHP?
The imagecreate[] function is an inbuilt function in PHP which is used to create a new image. This function returns the blank image of given size. In general imagecreatetruecolor[] function is used instead of imagecreate[] function because imagecreatetruecolor[] function creates high quality images.