How can the GDLib library be utilized in PHP for image manipulation?

GDLib library can be utilized in PHP for image manipulation by using functions like imagecreatefromjpeg, imagecopyresized, and imagejpeg. These functions allow you to create a new image from a JPEG file, resize images, and save them as JPEG files, respectively. By using these functions, you can easily manipulate images in PHP.

// Create a new image from a JPEG file
$source = imagecreatefromjpeg('image.jpg');

// Resize the image
$width = 200;
$height = 150;
$destination = imagecreatetruecolor($width, $height);
imagecopyresized($destination, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source));

// Save the resized image as a JPEG file
imagejpeg($destination, 'resized_image.jpg');

// Free up memory
imagedestroy($source);
imagedestroy($destination);