<?php
// File: create_logo.php

// --- SETTINGS ---
$savePath = "../ucf_logo.png"; // Where to save the file
$fontPath = __DIR__ . "/font.ttf";    // UPLOAD A FONT FILE HERE (e.g., arial.ttf)
$canvasSize = 500;                    // 500x500 pixels (High Quality)

// Check if GD Library is enabled
if (!extension_loaded('gd')) {
    die("Error: GD Library is not enabled on your server.");
}

// Check if Font exists
if (!file_exists($fontPath)) {
    die("Error: Font file not found. Please upload a .ttf file (like arial.ttf) to this folder and rename it to 'font.ttf'.");
}

// 1. Create the Canvas
$im = imagecreatetruecolor($canvasSize, $canvasSize);

// 2. Define Colors
// Alpha 127 means completely transparent
$transparent = imagecolorallocatealpha($im, 0, 0, 0, 127); 
$ucf_green   = imagecolorallocate($im, 22, 101, 52);   // #166534
$ucf_gold    = imagecolorallocate($im, 218, 165, 32);  // #DAA520
$white       = imagecolorallocate($im, 255, 255, 255);

// 3. Fill Background (Transparent)
imagefill($im, 0, 0, $transparent);
imagesavealpha($im, true); // Save transparency info

// 4. Draw the Outer Circle (Green)
$centerX = $canvasSize / 2;
$centerY = $canvasSize / 2;
$diameter = $canvasSize - 20; // Leave some padding

// Draw a filled circle
imagefilledellipse($im, $centerX, $centerY, $diameter, $diameter, $ucf_green);

// Draw an inner circle (White) to create a "Ring" effect
$borderThickness = 40;
$innerDiameter = $diameter - ($borderThickness * 2);
imagefilledellipse($im, $centerX, $centerY, $innerDiameter, $innerDiameter, $white);

// 5. Add Main Text "UCF"
$text = "UCF";
$fontSize = 100; // Large text
$angle = 0;

// Calculate text box to center it perfectly
$bbox = imagettfbbox($fontSize, $angle, $fontPath, $text);
$textWidth = $bbox[2] - $bbox[0];
$textHeight = $bbox[1] - $bbox[7];

$textX = $centerX - ($textWidth / 2);
$textY = $centerY + ($textHeight / 2) - 10; // Adjust slightly for baseline

// Draw Text in Green
imagettftext($im, $fontSize, $angle, $textX, $textY, $ucf_green, $fontPath, $text);

// 6. Add Subtitle "United Cultural Forum"
$subText = "United Cultural Forum";
$subFontSize = 22;

// Center Subtitle
$bboxSub = imagettfbbox($subFontSize, 0, $fontPath, $subText);
$subWidth = $bboxSub[2] - $bboxSub[0];
$subX = $centerX - ($subWidth / 2);
$subY = $centerY + 100; // Position below the main text

imagettftext($im, $subFontSize, 0, $subX, $subY, $ucf_gold, $fontPath, $subText);

// 7. Save the Image
// Check if directory exists
$dir = dirname($savePath);
if (!is_dir($dir)) {
    mkdir($dir, 0777, true);
}

if (imagepng($im, $savePath)) {
    // Clean up memory
    imagedestroy($im);
    
    echo "<h1>✅ Logo Generated Successfully!</h1>";
    echo "<p>Saved to: <strong>$savePath</strong></p>";
    echo "<p>Here is your new logo:</p>";
    echo "<div style='background:#eee; display:inline-block; padding:20px;'>";
    echo "<img src='$savePath' width='250' />";
    echo "</div>";
} else {
    echo "Error: Could not save image. Check folder permissions.";
}
?>