<?php
require("header.php")
?>

<?php
// Check if the form is submitted
if (isset($_POST['text1']) && isset($_POST['text2']) && isset($_POST['text3']) && isset($_POST['text4']) && isset($_POST['text5']) && isset($_POST['text6']) && isset($_POST['text8']) && isset($_POST['text9']) && isset($_POST['text10']) && isset($_POST['text11']) && isset($_POST['text12']) && isset($_POST['text13']) && isset($_POST['text14'])) {
    $text1 = $_POST['text1'];
    $text2 = $_POST['text2'];
    $text3 = $_POST['text3'];
    $text4 = $_POST['text4'];
    $text5 = $_POST['text5'];
    $text6 = $_POST['text6'];
    $text7 = $_POST['text7'];
    $text8 = $_POST['text8'];
    $text9 = $_POST['text9'];
    $text10 = $_POST['text10'];
    $text11 = $_POST['text11'];
    $text12 = $_POST['text12'];
    $text13 = $_POST['text13'];
    $text14 = $_POST['text14'];





    // Image path
    $imagePath = 'img/gen/ems-label.jpeg';

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

    // Define text color (black)
    $textColor = imagecolorallocate($image, 0, 0, 0);

    // Calculate the Y-coordinates for each text
    $y1 = 510;
    $y2 = 970;
    $y3 = 1430;
    $y4 = 1895;
    $y5 = 2360;
    $y6 = 2825;
    $y7 = 3285;
    $y8 = 510;
    $y9 = 970;
    $y10 = 1430;
    $y11 = 1895;
    $y12 = 2360;
    $y13 = 2825;
    $y14 = 3285;


    // Calculate the X-coordinates for each text
    $x1 = 350;
    $x2 = 350;
    $x3 = 350;
    $x4 = 350;
    $x5 = 350;
    $x6 = 350;
    $x7 = 350;
    $x8 = 1550;
    $x9 = 1550;
    $x10 = 1550;
    $x11 = 1550;
    $x12 = 1550;
    $x13 = 1550;
    $x14 = 1550;




    // Load font file
    $fontPath = 'img/gen/fonts/arial.ttf'; // Replace with the actual path to the font file


    // Define font size
    $fontSize = 55;


    // Apply faux bold effect to text for each option
    applyFauxBoldText($image, $fontSize, $x1, $y1, $textColor, $fontPath, $text1);
    applyFauxBoldText($image, $fontSize, $x2, $y2, $textColor, $fontPath, $text2);
    applyFauxBoldText($image, $fontSize, $x3, $y3, $textColor, $fontPath, $text3);
    applyFauxBoldText($image, $fontSize, $x4, $y4, $textColor, $fontPath, $text4);
    applyFauxBoldText($image, $fontSize, $x5, $y5, $textColor, $fontPath, $text5);
    applyFauxBoldText($image, $fontSize, $x6, $y6, $textColor, $fontPath, $text6);
    applyFauxBoldText($image, $fontSize, $x7, $y7, $textColor, $fontPath, $text7);
    applyFauxBoldText($image, $fontSize, $x8, $y8, $textColor, $fontPath, $text8);
    applyFauxBoldText($image, $fontSize, $x9, $y9, $textColor, $fontPath, $text9);
    applyFauxBoldText($image, $fontSize, $x10, $y10, $textColor, $fontPath, $text10);
    applyFauxBoldText($image, $fontSize, $x11, $y11, $textColor, $fontPath, $text11);
    applyFauxBoldText($image, $fontSize, $x12, $y12, $textColor, $fontPath, $text12);
    applyFauxBoldText($image, $fontSize, $x13, $y13, $textColor, $fontPath, $text13);
    applyFauxBoldText($image, $fontSize, $x14, $y14, $textColor, $fontPath, $text14);





    // Set image quality
    $quality = 100;

    // Change the save path and filename as needed
    $savePath = 'img/gen/ems/generated_image.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 fourteen 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>

    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th,
        td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }
    </style>
</head>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <!-- <h1>Panel Setting</h1> -->
                </div>
                <div class="col-sm-6">

                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                    <!-- Form Column -->
                    <div class="card card-secondary">
                        <div class="card-header" style="background-color: black;">
                            <h3 class="card-title">Create EMS Label</h3>
                            <ol class="breadcrumb float-sm-right" style="background-color: black;">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item">Tools</li>
                                <li class="breadcrumb-item active">EMS Label</li>
                            </ol>
                            <!-- Your existing card header code here -->
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <form action="ems-lable.php" method="post">

                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text1">Tracking 1</label>
                                                    <input type="text" class="form-control" id="text1" name="text1" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text2">Tracking 2</label>
                                                    <input type="text" class="form-control" id="text2" name="text2" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text3">Tracking 3</label>
                                                    <input type="text" class="form-control" id="text3" name="text3" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text4">Tracking 4</label>
                                                    <input type="text" class="form-control" id="text4" name="text4" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text5">Tracking 5</label>
                                                    <input type="text" class="form-control" id="text5" name="text5" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text6">Tracking 6</label>
                                                    <input type="text" class="form-control" id="text6" name="text6" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>



                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text7">Tracking 7</label>
                                                    <input type="text" class="form-control" id="text7" name="text7" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text8">Tracking 8</label>
                                                    <input type="text" class="form-control" id="text8" name="text8" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>



                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text9">Tracking 9</label>
                                                    <input type="text" class="form-control" id="text9" name="text9" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text10">Tracking 10</label>
                                                    <input type="text" class="form-control" id="text10" name="text10" placeholder="LP036254125IN">
                                                </div>

                                            </div>
                                        </div>


                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text11">Tracking 11</label>
                                                    <input type="text" class="form-control" id="text11" name="text11" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text12">Tracking 12</label>
                                                    <input type="text" class="form-control" id="text12" name="text12" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row">
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text13">Tracking 13</label>
                                                    <input type="text" class="form-control" id="text13" name="text13" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="form-group">
                                                    <label for="text14">Tracking 14</label>
                                                    <input type="text" class="form-control" id="text14" name="text14" placeholder="LP036254125IN">
                                                </div>
                                            </div>
                                        </div>

                                        <button type="submit" class="btn btn-primary mt-2" style="background:black;border:none">Generate Image</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-secondary">
                        <div class="card-header" style="background-color: black;">
                            <h3 class="card-title">Preview EMS Label</h3>
                            <!-- Your existing card header code here -->
                        </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-dark mt-2">Download Image</a>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>

            </div>
        </div><!-- /.container-fluid -->
    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<!-- Your existing scripts and footer here -->

<script>
    var loadFile = function(event) {
        var image = document.getElementById('output');
        image.src = URL.createObjectURL(event.target.files[0]);
    };
</script>
<!-- searching end -->

<!-- pagination -->

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