<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Start session
session_start();
echo "<h1>Creating Local Placeholder Images</h1>";
// Create directories if they don't exist
$directories = [
'assets/images',
'assets/images/courses',
'assets/images/testimonials',
'assets/images/team',
'assets/images/blog',
'assets/images/hero'
];
foreach ($directories as $dir) {
if (!file_exists($dir)) {
if (mkdir($dir, 0755, true)) {
echo "<p>Created directory: $dir</p>";
} else {
echo "<p style='color: red;'>Failed to create directory: $dir</p>";
}
} else {
echo "<p>Directory already exists: $dir</p>";
}
}
// Function to create a placeholder image
function createPlaceholder($width, $height, $bgColor, $textColor, $text, $path) {
// Check if file already exists
if (file_exists($path)) {
echo "<p style='color: blue;'>File already exists: $path</p>";
return true;
}
// Create image
$im = imagecreatetruecolor($width, $height);
// Convert hex to RGB
$bgRGB = sscanf($bgColor, "%2x%2x%2x");
$textRGB = sscanf($textColor, "%2x%2x%2x");
// Create colors
$bg = imagecolorallocate($im, $bgRGB[0], $bgRGB[1], $bgRGB[2]);
$text_color = imagecolorallocate($im, $textRGB[0], $textRGB[1], $textRGB[2]);
// Fill background
imagefilledrectangle($im, 0, 0, $width, $height, $bg);
// Center text
$font = 5; // Built-in font
$textWidth = imagefontwidth($font) * strlen($text);
$textHeight = imagefontheight($font);
$x = ($width - $textWidth) / 2;
$y = ($height - $textHeight) / 2;
imagestring($im, $font, $x, $y, $text, $text_color);
// Save image
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ($extension == 'jpg' || $extension == 'jpeg') {
$result = imagejpeg($im, $path, 90);
} else if ($extension == 'png') {
$result = imagepng($im, $path);
} else {
$result = imagepng($im, $path);
}
imagedestroy($im);
if ($result) {
echo "<p style='color: green;'>Created placeholder image: $path</p>";
return true;
} else {
echo "<p style='color: red;'>Failed to create placeholder image: $path</p>";
return false;
}
}
// Images to create
$images = [
// Logo
[
'width' => 200,
'height' => 60,
'bgColor' => '4e73df',
'textColor' => 'ffffff',
'text' => 'YourLogo',
'path' => 'assets/images/logo.png',
'type' => 'Logo'
],
// Hero images
[
'width' => 1920,
'height' => 800,
'bgColor' => '1cc88a',
'textColor' => 'ffffff',
'text' => 'Hero Image 1',
'path' => 'assets/images/hero/hero1.jpg',
'type' => 'Hero'
],
[
'width' => 1920,
'height' => 800,
'bgColor' => '36b9cc',
'textColor' => 'ffffff',
'text' => 'Hero Image 2',
'path' => 'assets/images/hero/hero2.jpg',
'type' => 'Hero'
],
// Course images
[
'width' => 600,
'height' => 400,
'bgColor' => '4e73df',
'textColor' => 'ffffff',
'text' => 'Course 1',
'path' => 'assets/images/courses/course1.jpg',
'type' => 'Course'
],
[
'width' => 600,
'height' => 400,
'bgColor' => '1cc88a',
'textColor' => 'ffffff',
'text' => 'Course 2',
'path' => 'assets/images/courses/course2.jpg',
'type' => 'Course'
],
[
'width' => 600,
'height' => 400,
'bgColor' => '36b9cc',
'textColor' => 'ffffff',
'text' => 'Course 3',
'path' => 'assets/images/courses/course3.jpg',
'type' => 'Course'
],
[
'width' => 600,
'height' => 400,
'bgColor' => 'f6c23e',
'textColor' => 'ffffff',
'text' => 'Course 4',
'path' => 'assets/images/courses/course4.jpg',
'type' => 'Course'
],
// Team members
[
'width' => 300,
'height' => 300,
'bgColor' => '4e73df',
'textColor' => 'ffffff',
'text' => 'Team 1',
'path' => 'assets/images/team/team1.jpg',
'type' => 'Team'
],
[
'width' => 300,
'height' => 300,
'bgColor' => '1cc88a',
'textColor' => 'ffffff',
'text' => 'Team 2',
'path' => 'assets/images/team/team2.jpg',
'type' => 'Team'
],
[
'width' => 300,
'height' => 300,
'bgColor' => '36b9cc',
'textColor' => 'ffffff',
'text' => 'Team 3',
'path' => 'assets/images/team/team3.jpg',
'type' => 'Team'
],
// Testimonials
[
'width' => 150,
'height' => 150,
'bgColor' => '4e73df',
'textColor' => 'ffffff',
'text' => 'User 1',
'path' => 'assets/images/testimonials/user1.jpg',
'type' => 'Testimonial'
],
[
'width' => 150,
'height' => 150,
'bgColor' => '1cc88a',
'textColor' => 'ffffff',
'text' => 'User 2',
'path' => 'assets/images/testimonials/user2.jpg',
'type' => 'Testimonial'
],
[
'width' => 150,
'height' => 150,
'bgColor' => '36b9cc',
'textColor' => 'ffffff',
'text' => 'User 3',
'path' => 'assets/images/testimonials/user3.jpg',
'type' => 'Testimonial'
],
// Blog posts
[
'width' => 800,
'height' => 500,
'bgColor' => '4e73df',
'textColor' => 'ffffff',
'text' => 'Blog Post 1',
'path' => 'assets/images/blog/post1.jpg',
'type' => 'Blog'
],
[
'width' => 800,
'height' => 500,
'bgColor' => '1cc88a',
'textColor' => 'ffffff',
'text' => 'Blog Post 2',
'path' => 'assets/images/blog/post2.jpg',
'type' => 'Blog'
],
[
'width' => 800,
'height' => 500,
'bgColor' => '36b9cc',
'textColor' => 'ffffff',
'text' => 'Blog Post 3',
'path' => 'assets/images/blog/post3.jpg',
'type' => 'Blog'
]
];
// Create images
echo "<h2>Creating Images</h2>";
$success_count = 0;
$failed_count = 0;
foreach ($images as $image) {
echo "<h3>Processing {$image['type']} Image</h3>";
if (createPlaceholder(
$image['width'],
$image['height'],
$image['bgColor'],
$image['textColor'],
$image['text'],
$image['path']
)) {
$success_count++;
} else {
$failed_count++;
}
}
echo "<h2>Image Creation Summary</h2>";
echo "<p>Successfully created: $success_count images</p>";
echo "<p>Failed to create: $failed_count images</p>";
// Create a CSS file with image references
$css_content = <<<CSS
/* Sample CSS for images */
.logo {
background-image: url('../images/logo.png');
background-size: contain;
background-repeat: no-repeat;
}
.hero-section {
background-image: url('../images/hero/hero1.jpg');
background-size: cover;
background-position: center;
}
.course-1 {
background-image: url('../images/courses/course1.jpg');
}
.course-2 {
background-image: url('../images/courses/course2.jpg');
}
.course-3 {
background-image: url('../images/courses/course3.jpg');
}
.course-4 {
background-image: url('../images/courses/course4.jpg');
}
.team-member-1 {
background-image: url('../images/team/team1.jpg');
}
.team-member-2 {
background-image: url('../images/team/team2.jpg');
}
.team-member-3 {
background-image: url('../images/team/team3.jpg');
}
.testimonial-1 {
background-image: url('../images/testimonials/user1.jpg');
}
.testimonial-2 {
background-image: url('../images/testimonials/user2.jpg');
}
.testimonial-3 {
background-image: url('../images/testimonials/user3.jpg');
}
.blog-post-1 {
background-image: url('../images/blog/post1.jpg');
}
.blog-post-2 {
background-image: url('../images/blog/post2.jpg');
}
.blog-post-3 {
background-image: url('../images/blog/post3.jpg');
}
CSS;
if (file_put_contents('assets/css/images.css', $css_content)) {
echo "<p style='color: green;'>Created CSS file with image references: assets/css/images.css</p>";
} else {
echo "<p style='color: red;'>Failed to create CSS file</p>";
}
echo "<h2>Next Steps</h2>";
echo "<p>1. Include the CSS file in your HTML:</p>";
echo "<pre><link rel='stylesheet' href='assets/css/images.css'></pre>";
echo "<p>2. Use the CSS classes in your HTML elements:</p>";
echo "<pre><div class='hero-section'>...</div></pre>";
echo "<p>3. Or use the images directly in your HTML:</p>";
echo "<pre><img src='assets/images/logo.png' alt='Logo'></pre>";
echo "<h2>Navigation</h2>";
echo "<p><a href='index.php' style='background-color: #4e73df; color: white; padding: 10px 15px; text-decoration: none; border-radius: 5px; margin-right: 10px;'>Go to Homepage</a>";
echo "<a href='admin/check_dashboard.php' style='background-color: #1cc88a; color: white; padding: 10px 15px; text-decoration: none; border-radius: 5px;'>Check Admin Dashboard</a></p>";
?>