<!DOCTYPE html>
<html lang="en">
<?php
// Check if the form is submitted
if (isset($_POST['text1']) && isset($_POST['text2'])) {
    $text1 = $_POST['text1'];
    $text2 = $_POST['text2'];

    // Image path
    $imagePath = 'slip/phone-pay.jpg';

    // Load the image
    $image = imagecreatefromjpeg($imagePath);

    // Define text color (black)
    $textColor = imagecolorallocate($image, 237, 240, 244);

    // Calculate the Y-coordinates for each text
    $y = 200;
    
    // Calculate the X-coordinates for each text
    $x = 335;
   
    // Load different font files for each text
    $fontPath = 'slip/fonts/Myriad Pro Regular.ttf'; // Replace with the actual path to the font file for Text 1
    
    // Define font sizes for each text
    $fontSize = 55;
    
    // Add text to the image using different fonts and font sizes
    applyFauxBoldText($image, $fontSize, $x, $y, $textColor, $fontPath, $text);
    
    // Set image quality
    $quality = 100;

    // Change the save path and filename as needed
    $timestamp = time();
    $savePath = "slip/gen/phonepay/generated_image_$timestamp.jpg";
    imagejpeg($image, $savePath, $quality);

    // Free up memory
    imagedestroy($image);

    // Provide the URL of the saved image for preview and download
    $imageURL = $savePath;
} else {
    echo "Please enter all three texts.";
}

function applyFauxBoldText($image, $fontSize, $x, $y, $color, $fontPath, $text)
{
    $offset = 1; // Adjust the offset to control the faux bold effect
    for ($i = 0; $i < $offset; $i++) {
        imagettftext($image, $fontSize, 0, $x + $i, $y, $color, $fontPath, $text);
    }
}
?>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : Add Expenses</title>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
    <?php include("headerlink.php") ?>
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">

        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>

        <?php include("navbar.php") ?>
        <?php include("sidebar.php") ?>

        <div class="content-wrapper">

            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-bold text-uppercase">Interview Task</h1>
                        </div>

                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <!-- <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Inventory</li>
                                <li class="breadcrumb-item active">Expenses</li> -->
                            </ol>
                        </div>
                    </div>
                </div>
            </div>



            <section class="content">
                <div class="container-fluid">
                    <div class="row">

                        <div class="col-md-12">

                            <div class="card card-primary">
                                <div class="card-header  " style="background: #343a40;">
                                    <h3 class="card-title fw-bold text-uppercase">PHP developer</h3>
                                </div>
                                <div class="row pt-4">
                                    <div class="col-md-6">
                                        <!-- Form Column -->
                                        <div class="card card-dark">
                                            
                                            <div class="card-header" style="height: 50px;">
                                                <div class="row">
                                                    <div class="col-8">
                                                        <h3 class="card-title fw-bold">Enter Website URLs</h3>
                                                    </div>
                                                    <div class="col-4">
                                                        <p class="text-end fw-bold ">Tools&nbsp;/&nbsp;USDT Receipt</p>
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="card-body">
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <form action="phonepay-icici.php" method="post">
                                                            <div class="form-group">
                                                                <label for="text1">Amount</label>
                                                                <input type="text" class="form-control" id="text1"
                                                                    name="text1" placeholder="356">
                                                            </div>
                                                            <div class="form-group">
                                                                <label for="text2">Date and Time</label>
                                                                <input type="text" class="form-control" id="text2"
                                                                    name="text2" placeholder="2023-08-11 20:13:02">
                                                            </div>
                                                            <button type="submit" class="btn btn-primary mt-2"
                                                                style="background: #343a40;border:none">Create</button>
                                                        </form>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <!-- Placeholder for image previews or any other content -->
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <!-- Image Preview Column -->
                                        <div class="card card-dark">
                                            <div class="card-header ">
                                                <h3 class="card-title">Image Preview</h3>
                                               
                                            </div>
                                            <div class="card-body">
                                                <?php if (isset($imageURL)) : ?>
                                                <img src="<?php echo $imageURL; ?>" alt="Generated Image"
                                                    class="img-fluid">
                                                <a href="<?php echo $imageURL; ?>" download
                                                    class="btn btn-primary mt-2">Download Image</a>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                            </div>

                        </div>

                    </div>

                </div>
            </section>
        </div>

        <?php include("footer.php") ?>


    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <script>
    $(document).ready(function() {
        <?php if (isset($_GET['error'])) { ?>
        Swal.fire({
            title: 'Error',
            text: '<?php echo $_GET['error']; ?>',
            icon: 'error',
            confirmButtonText: 'OK',
            confirmButtonClass: 'btn btn-success btn-lg',
        });
        <?php } ?>
        <?php if (isset($_GET['success'])) { ?>
        Swal.fire({
            title: 'Success',
            text: '<?php echo $_GET['success']; ?>',
            icon: 'success',
            confirmButtonText: 'OK',
            confirmButtonClass: 'btn btn-success btn-lg',
        });
        <?php } ?>
    });
    </script>
    <script>
    var $j = jQuery.noConflict();
    $j(document).ready(function() {
        $j('#example2').DataTable();
    });
    </script>
    <?php include("footerlink.php") ?>
</body>

</html>