The php Function Imagecolorallocate
The php function imagecolorallocate is one of the fundamental functions used in PHP GD (Graphics Datatype) library. PHP GD is an advanced image manipulation library that is built into the PHP engine and provides a powerful way to dynamically draw and manipulate images within your web pages. The GD library also allows you to create GIF, JPEG and PNG files with alpha transparency.
For the purposes of this article we will be using an existing PNG file as our canvas and we will be focusing on the GD functions that allow you to draw lines and other shapes. First you will need to have the GD library installed on your system. This can usually be done by your host or by installing the GD library manually.
In the following example we will be drawing a line between two points on the image. The first point will be 30 pixels from the left edge of the image and the second point will be 165 pixels from that same edge. The line color will be a shade of green that we have previously created with the imagecolorallocate() function.
In order to do this you will need to pass the following parameters to the imageline() function: