Path : /home/vishqocm/pcib.in/
File Upload :
Current File : /home/vishqocm//pcib.in/generate_images.php

<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Set maximum execution time to 5 minutes
ini_set('max_execution_time', 300);

// Start session
session_start();

// Function to create directory if it doesn't exist
function createDir($dir) {
    if (!file_exists($dir)) {
        mkdir($dir, 0777, true);
    }
}

// Function to create a placeholder image
function createPlaceholder($width, $height, $bg_color, $text_color, $text, $file_path) {
    // Check if file already exists
    if (file_exists($file_path)) {
        return true;
    }
    
    // Create image
    $image = imagecreatetruecolor($width, $height);
    
    // Convert hex colors to RGB
    list($r1, $g1, $b1) = sscanf($bg_color, "#%02x%02x%02x");
    list($r2, $g2, $b2) = sscanf($text_color, "#%02x%02x%02x");
    
    // Allocate colors
    $bg = imagecolorallocate($image, $r1, $g1, $b1);
    $text_color = imagecolorallocate($image, $r2, $g2, $b2);
    
    // Fill background
    imagefill($image, 0, 0, $bg);
    
    // Add text
    $font_size = 5;
    $text_width = imagefontwidth($font_size) * strlen($text);
    $text_height = imagefontheight($font_size);
    
    $x = ($width - $text_width) / 2;
    $y = ($height - $text_height) / 2;
    
    imagestring($image, $font_size, $x, $y, $text, $text_color);
    
    // Create directory if it doesn't exist
    $dir = dirname($file_path);
    createDir($dir);
    
    // Save image
    imagepng($image, $file_path);
    
    // Free memory
    imagedestroy($image);
    
    return true;
}

// Create directories
createDir('assets/images/logo');
createDir('assets/images/hero');
createDir('assets/images/courses');
createDir('assets/images/team');
createDir('assets/images/testimonials');
createDir('assets/images/blog');
createDir('assets/images/profile');

// Define images to create
$images = [
    // Logo
    [
        'width' => 200,
        'height' => 60,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'LMS Logo',
        'file_path' => 'assets/images/logo.png'
    ],
    
    // Hero images
    [
        'width' => 1920,
        'height' => 600,
        'bg_color' => '#343a40',
        'text_color' => '#ffffff',
        'text' => 'Hero Image 1',
        'file_path' => 'assets/images/hero/hero1.jpg'
    ],
    [
        'width' => 800,
        'height' => 600,
        'bg_color' => '#6c757d',
        'text_color' => '#ffffff',
        'text' => 'Hero Image 2',
        'file_path' => 'assets/images/hero/hero2.jpg'
    ],
    
    // Course images
    [
        'width' => 400,
        'height' => 200,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'Web Development',
        'file_path' => 'assets/images/courses/1.jpg'
    ],
    [
        'width' => 400,
        'height' => 200,
        'bg_color' => '#1cc88a',
        'text_color' => '#ffffff',
        'text' => 'Data Science',
        'file_path' => 'assets/images/courses/2.jpg'
    ],
    [
        'width' => 400,
        'height' => 200,
        'bg_color' => '#36b9cc',
        'text_color' => '#ffffff',
        'text' => 'Digital Marketing',
        'file_path' => 'assets/images/courses/3.jpg'
    ],
    [
        'width' => 400,
        'height' => 200,
        'bg_color' => '#f6c23e',
        'text_color' => '#ffffff',
        'text' => 'Graphic Design',
        'file_path' => 'assets/images/courses/4.jpg'
    ],
    
    // Team images
    [
        'width' => 300,
        'height' => 300,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'Team Member 1',
        'file_path' => 'assets/images/team/team1.jpg'
    ],
    [
        'width' => 300,
        'height' => 300,
        'bg_color' => '#1cc88a',
        'text_color' => '#ffffff',
        'text' => 'Team Member 2',
        'file_path' => 'assets/images/team/team2.jpg'
    ],
    [
        'width' => 300,
        'height' => 300,
        'bg_color' => '#36b9cc',
        'text_color' => '#ffffff',
        'text' => 'Team Member 3',
        'file_path' => 'assets/images/team/team3.jpg'
    ],
    
    // Testimonial images
    [
        'width' => 100,
        'height' => 100,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'User 1',
        'file_path' => 'assets/images/testimonials/user1.jpg'
    ],
    [
        'width' => 100,
        'height' => 100,
        'bg_color' => '#1cc88a',
        'text_color' => '#ffffff',
        'text' => 'User 2',
        'file_path' => 'assets/images/testimonials/user2.jpg'
    ],
    [
        'width' => 100,
        'height' => 100,
        'bg_color' => '#36b9cc',
        'text_color' => '#ffffff',
        'text' => 'User 3',
        'file_path' => 'assets/images/testimonials/user3.jpg'
    ],
    
    // Blog images
    [
        'width' => 800,
        'height' => 400,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'Blog Post 1',
        'file_path' => 'assets/images/blog/post1.jpg'
    ],
    [
        'width' => 800,
        'height' => 400,
        'bg_color' => '#1cc88a',
        'text_color' => '#ffffff',
        'text' => 'Blog Post 2',
        'file_path' => 'assets/images/blog/post2.jpg'
    ],
    [
        'width' => 800,
        'height' => 400,
        'bg_color' => '#36b9cc',
        'text_color' => '#ffffff',
        'text' => 'Blog Post 3',
        'file_path' => 'assets/images/blog/post3.jpg'
    ],
    
    // Default profile image
    [
        'width' => 200,
        'height' => 200,
        'bg_color' => '#4e73df',
        'text_color' => '#ffffff',
        'text' => 'Profile',
        'file_path' => 'assets/images/profile/default.jpg'
    ]
];

// Create images
$success_count = 0;
$error_count = 0;

echo '<h1>Generating Placeholder Images</h1>';
echo '<div style="font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto;">';

foreach ($images as $image) {
    echo '<p>Creating image: ' . $image['file_path'] . ' ... ';
    
    try {
        if (createPlaceholder(
            $image['width'],
            $image['height'],
            $image['bg_color'],
            $image['text_color'],
            $image['text'],
            $image['file_path']
        )) {
            echo '<span style="color: green;">Success</span></p>';
            $success_count++;
        } else {
            echo '<span style="color: red;">Failed</span></p>';
            $error_count++;
        }
    } catch (Exception $e) {
        echo '<span style="color: red;">Error: ' . $e->getMessage() . '</span></p>';
        $error_count++;
    }
}

// Create CSS file with image references
$css_content = "/* Generated image references */\n\n";
$css_content .= ".course-1 { background-image: url('../images/courses/1.jpg'); }\n";
$css_content .= ".course-2 { background-image: url('../images/courses/2.jpg'); }\n";
$css_content .= ".course-3 { background-image: url('../images/courses/3.jpg'); }\n";
$css_content .= ".course-4 { background-image: url('../images/courses/4.jpg'); }\n";

// Create directory if it doesn't exist
createDir('assets/css');

// Write CSS file
file_put_contents('assets/css/images.css', $css_content);

echo '<h2>Summary</h2>';
echo '<p>Total images: ' . count($images) . '</p>';
echo '<p>Successfully created: ' . $success_count . '</p>';
echo '<p>Failed: ' . $error_count . '</p>';

echo '<h2>Next Steps</h2>';
echo '<ol>';
echo '<li>Include the CSS file in your HTML: <code>&lt;link rel="stylesheet" href="assets/css/images.css"&gt;</code></li>';
echo '<li>Use the generated images in your website</li>';
echo '</ol>';

echo '<p><a href="fixed_index.php" style="display: inline-block; padding: 10px 20px; background-color: #4e73df; color: white; text-decoration: none; border-radius: 5px;">View Website</a></p>';

echo '</div>';
?>