What is the function imagecopy in PHP used for?

The function imagecopy in PHP is used to copy a portion of one image onto another image. This can be useful when you want to merge two images together or overlay one image onto another. By specifying the source and destination images, as well as the coordinates and dimensions of the portion to copy, you can achieve the desired effect.

// Example of using imagecopy to copy a portion of one image onto another
$source = imagecreatefromjpeg('source.jpg');
$destination = imagecreatefromjpeg('destination.jpg');

// Copy a portion of the source image onto the destination image
imagecopy($destination, $source, 0, 0, 0, 0, 100, 100);

// Output the resulting image
header('Content-Type: image/jpeg');
imagejpeg($destination);

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