What is the purpose of using the ImageCreate function in PHP for creating images?

The ImageCreate function in PHP is used to create a new image resource with a specified width and height. This function is commonly used in image manipulation tasks such as creating thumbnails, adding watermarks, or generating dynamic images on the fly. By using ImageCreate, developers can easily generate and manipulate images within their PHP scripts.

// Create a new image with width 200 and height 100
$image = ImageCreate(200, 100);

// Set the background color to white
$white = ImageColorAllocate($image, 255, 255, 255);
ImageFill($image, 0, 0, $white);

// Output the image to the browser
header('Content-type: image/png');
ImagePNG($image);

// Free up memory
ImageDestroy($image);