Skip to content

Commit

Permalink
adding the PHP files for live testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rnddave committed May 14, 2024
1 parent 37beb4b commit ebd7fb5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
41 changes: 41 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>QR Code Generator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
input[type="text"] {
padding: 5px;
font-size: 16px;
width: 300px;
}
button {
padding: 5px 10px;
font-size: 16px;
}
img {
max-width: 300px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>QR Code Generator</h1>
<form method="get" action="qr-generator.php">
<label for="url">Enter a URL:</label>
<input type="text" id="url" name="url" placeholder="https://www.example.com">
<button type="submit">Generate QR Code</button>
</form>

<?php
if (isset($_GET['url'])) {
$url = $_GET['url'];
echo "<img src=\"qr-generator.php?url=$url\" alt=\"QR Code\">";
}
?>
</body>
</html>
32 changes: 32 additions & 0 deletions qr-generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require 'vendor/autoload.php';

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Label\Label;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;

// Get the URL from the user input (you can replace this with your own method of obtaining the URL)
$url = isset($_GET['url']) ? $_GET['url'] : 'https://www.example.com';

// Create a basic QR code
$qrCode = new QrCode($url);
$writer = new PngWriter();

// Customize the QR code
$qrCode
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255))
->setLabel('My QR Code')
->setLogoPath(__DIR__ . '/logo.png');

// Save the QR code as a PNG image
$result = $writer->write($qrCode);
header('Content-Type: ' . $result->getMimeType());
echo $result->getString();

0 comments on commit ebd7fb5

Please sign in to comment.