Creating Basic Images in PHP

PHP can do a lot more than generate dynamic HTML, it can also generate images. There could be many reasons why you would need dynamically generated images over standard images, like creating buttons from text fields in a database or creating visual graphs from web site usage or ecommerce data. PHP also allows the image to be in a variety of formats like JPEG, GIF, BMP, and PNG.

PHP uses the function imagecreate, which takes at least two parameters (the width and height) of the image to return the handle for the image or the resource identifier. To use colors, the color must be allocated in a resource identifier using the function ImageColorAllocate($(Image Handle),RED,GREEN,BLUE). That function returns the handle or resource identifier for the color selected, which then can be used with functions like imagechar, imagefill, imagefilledrectangle, imagefilledpolygon, and imagestring.