<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
    $image = $_FILES['image']['tmp_name'];

    if (file_exists($image) && exif_imagetype($image) !== false) {
        $favicon = imagecreatefromstring(file_get_contents($image));
        $size = getimagesize($image);
        $favicon = imagescale($favicon, 16, 16); // Resize the image to 16x16 for the favicon

        // Set the headers to trigger the download
        header('Content-Type: image/x-icon');
        header('Content-Disposition: attachment; filename="favicon.ico"');

        // Output the image data directly to the browser
        imagepng($favicon);
        imagedestroy($favicon);
        exit;
    }
}
?>



<!DOCTYPE html>
<html>
<head>
    <title>Favicon Generator</title>
    <meta charset="utf-8" />
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .container {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
        }
        .form-group label {
            display: block;
            margin-bottom: 10px;
        }
        .form-group input[type="file"] {
            width: 90%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        button {
            display: block;
            margin-top: 10px;
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>Favicon Generator</h1>
    <form method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="image">Select an image:</label>
            <input type="file" name="image" id="image" accept="image/*" required>
        </div>
        <button type="submit">Generate Favicon</button>
    </form>
</div>
</body>
</html>
