generate image in php

To generate an image in PHP, you can use the GD library which provides functions for creating and manipulating images. Here's an example code to generate a simple image in PHP:

main.php
<?php
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

// Create a blank image with dimensions 200x200
$image = imagecreatetruecolor(200, 200);

// Set the background color as white
$bgColor = imagecolorallocate($image, 255, 255, 255);

// Fill the image with the background color
imagefill($image, 0, 0, $bgColor);

// Output the image as JPEG
imagejpeg($image);

// Free up memory
imagedestroy($image);
?>
453 chars
20 lines

In the above code, you create a blank image using imagecreatetruecolor() function, set the background color, fill the image with the color, output the image as JPEG using imagejpeg() function, and finally free up memory using imagedestroy() function.

related categories

gistlibby LogSnag