How can PHP be used to create and manipulate images, such as adding text and combining multiple images?

To create and manipulate images in PHP, you can use the GD library which provides functions for image processing. You can use functions like imagecreatefromjpeg(), imagecopy(), imagettftext() to create, manipulate, and add text to images. You can also use imagepng(), imagejpeg() functions to save the final image.

// Create a new image from an existing image
$baseImage = imagecreatefromjpeg('base.jpg');

// Load a font
$font = 'arial.ttf';

// Add text to the image
$textColor = imagecolorallocate($baseImage, 255, 255, 255);
imagettftext($baseImage, 20, 0, 10, 30, $textColor, $font, 'Hello World');

// Save the final image
imagejpeg($baseImage, 'output.jpg');

// Free up memory
imagedestroy($baseImage);