What is the purpose of using GD Lib in PHP for creating images?

GD Lib in PHP is used for creating and manipulating images dynamically. It allows you to generate images on-the-fly, resize, crop, add text, draw shapes, and apply various filters to images. This can be useful for generating charts, graphs, thumbnails, or custom images based on user input or specific requirements.

// Example code to create a simple image using GD Lib
$width = 200;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$bg_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $bg_color);
imagestring($image, 5, 50, 40, 'Hello, World!', $text_color);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);