<?php
// Simple script to create default slider images
// Set up folder
$slider_dir = __DIR__ . '/../assets/img/slider';
if (!file_exists($slider_dir)) {
if (!mkdir($slider_dir, 0755, true)) {
die("Failed to create slider directory. Please check permissions.");
}
}
// Create placeholder images
$images = [
[
'name' => 'default-slide-1.jpg',
'text' => 'Empowering Future Technology Leaders',
'color' => [66, 133, 244] // Blue
],
[
'name' => 'default-slide-2.jpg',
'text' => 'Learn From Industry Experts',
'color' => [219, 68, 55] // Red
],
[
'name' => 'default-slide-3.jpg',
'text' => 'Achieve Your Career Goals',
'color' => [15, 157, 88] // Green
]
];
header('Content-Type: text/html');
echo "<h1>Creating Slider Images</h1>";
foreach ($images as $image) {
$image_path = $slider_dir . '/' . $image['name'];
// Create a colored image with text
$width = 1920;
$height = 1080;
$img = imagecreatetruecolor($width, $height);
// Background color
$bg = imagecolorallocate($img, $image['color'][0], $image['color'][1], $image['color'][2]);
imagefill($img, 0, 0, $bg);
// Add some design elements (gradient overlay)
$black = imagecolorallocatealpha($img, 0, 0, 0, 80);
for ($y = 0; $y < $height; $y += 2) {
// Create a gradient effect
$opacity = 127 - (($y / $height) * 90);
$line_color = imagecolorallocatealpha($img, 0, 0, 0, $opacity);
imageline($img, 0, $y, $width, $y, $line_color);
}
// Add text
$white = imagecolorallocate($img, 255, 255, 255);
$font_path = realpath(__DIR__ . '/fonts/arial.ttf');
// If font doesn't exist, use default
if (!file_exists($font_path)) {
$font_path = 5; // Use built-in font
// Draw text with built-in font
$text = $image['text'];
$text_width = imagefontwidth(5) * strlen($text);
$text_height = imagefontheight(5);
$x = ($width - $text_width) / 2;
$y = ($height - $text_height) / 2;
imagestring($img, 5, $x, $y, $text, $white);
} else {
// Calculate position for centered text (TTF font)
$font_size = 40;
$text = $image['text'];
$box = imagettfbbox($font_size, 0, $font_path, $text);
$text_width = $box[2] - $box[0];
$text_height = $box[1] - $box[7];
$x = ($width - $text_width) / 2;
$y = ($height + $text_height) / 2;
imagettftext($img, $font_size, 0, $x, $y, $white, $font_path, $text);
}
// Save the image
imagejpeg($img, $image_path, 90);
imagedestroy($img);
echo "<div style='margin-bottom: 20px;'>";
echo "<p>Created image: {$image['name']}</p>";
echo "<img src='../assets/img/slider/{$image['name']}' style='max-width: 400px; border: 1px solid #ccc;'>";
echo "</div>";
}
echo "<p>All slider images have been created successfully!</p>";
echo "<p><a href='sliders.php'>Go to Slider Management</a></p>";
?>