How can PHP developers effectively utilize the imagecopy function for image manipulation?
To effectively utilize the imagecopy function for image manipulation in PHP, developers can use it to copy a portion of one image onto another image. This can be useful for tasks like creating image thumbnails, combining images, or applying watermarks.
// Load the source and destination images
$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);
// Save the modified image
imagejpeg($destination, 'output.jpg');
// Free up memory
imagedestroy($source);
imagedestroy($destination);