How can you overlay points or crosses on an image in PHP without altering the original image?

To overlay points or crosses on an image in PHP without altering the original image, you can create a new image with the same dimensions as the original image, copy the original image onto the new image, draw points or crosses on the new image using PHP's GD library, and then output or save the new image without affecting the original.

// Load the original image
$original_image = imagecreatefromjpeg('original.jpg');

// Create a new image with the same dimensions
$new_image = imagecreatetruecolor(imagesx($original_image), imagesy($original_image));

// Copy the original image onto the new image
imagecopy($new_image, $original_image, 0, 0, 0, 0, imagesx($original_image), imagesy($original_image));

// Draw points or crosses on the new image
$color = imagecolorallocate($new_image, 255, 0, 0);
imagesetpixel($new_image, 50, 50, $color);
imageline($new_image, 100, 100, 150, 150, $color);

// Output or save the new image
header('Content-Type: image/jpeg');
imagejpeg($new_image, 'output.jpg');

// Free up memory
imagedestroy($original_image);
imagedestroy($new_image);