<?php
// Retrieve shipment details from the URL
$tracking_number = $_GET['tracking_number'];
$receiver_name = $_GET['receiver_name'];
$sender_name = $_GET['sender_name'];
$origin = $_GET['origin'];
$destination = $_GET['destination'];
$receiver_address = $_GET['receiver_address'];
$shipment_type = $_GET['shipment_type'];
$weight = $_GET['weight'];
$delivery_date = $_GET['delivery_date'];
$status = $_GET['status'];

// Create an image using GD Library
$width = 600;
$height = 800;
$image = imagecreatetruecolor($width, $height);

// Define colors
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 0, 86, 179);

// Fill the background with white
imagefilledrectangle($image, 0, 0, $width, $height, $white);

// Add header
imagettftext($image, 24, 0, 50, 60, $blue, 'arial.ttf', 'Shipping Receipt');
imagettftext($image, 14, 0, 50, 100, $black, 'arial.ttf', "Tracking Number: $tracking_number");

// Add shipment details
$y = 150;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Receiver: $receiver_name");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Sender: $sender_name");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Origin: $origin");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Destination: $destination");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Delivery Address: $receiver_address");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Package Type: $shipment_type");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Weight: $weight kg");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Expected Delivery Date: $delivery_date");
$y += 30;
imagettftext($image, 12, 0, 50, $y, $black, 'arial.ttf', "Status: $status");

// Add footer
imagettftext($image, 10, 0, 50, $height - 50, $black, 'arial.ttf', "Thank you for choosing our shipping services!");

// Output the image as a PNG file
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="receipt.png"');
imagepng($image);

// Free up memory
imagedestroy($image);
?>