<?php
// header_image.php
header("Content-Type: image/png");

// Get text from URL
$text = $_GET['text'] ?? 'Header';

// Image size (make bigger so text doesn't cut off)
$width  = 300;
$height = 120;

// Create transparent canvas
$image = imagecreatetruecolor($width, $height);
imagesavealpha($image, true);
$transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $transparent);

// Set text color (black)
$black = imagecolorallocate($image, 0, 0, 0);

// Path to your font in mPDF
// Example: DejaVuSans.ttf (ships with mPDF)
$font = __DIR__ . "/vendor/mpdf/mpdf/ttfonts/DejaVuSans.ttf";

// Adjust if you want another font (e.g., "times.ttf")
if (!file_exists($font)) {
    die("Font not found: $font");
}

// Font size
$fontSize = 14;

// Add text rotated at -45 degrees
// X=20, Y=100 → adjust positioning if text is cut off
imagettftext($image, $fontSize, -45, 20, 100, $black, $font, $text);

// Output PNG
imagepng($image);
imagedestroy($image);
