<?php
// Include QR library
include 'qrlib.php'; // Make sure this file exists in same folder

// Set directory where QR codes will be saved
$save_dir = __DIR__ . '/saved_qrcodes/';

// Create folder if not exists
if (!is_dir($save_dir)) {
    mkdir($save_dir, 0777, true);
}

// Text you want to put in QR code
$your_text = "http://localhost/mysite/ab/make-id/phpqrcode-master/ab.php";

// Generate a unique filename
$filename = $save_dir . uniqid('qr_') . '.png';

// Set QR options
$errorCorrectionLevel = 'H'; // L = lowest, H = best
$matrixPointSize = 10; // Size (1 to 10)

// Step 1: Create and save QR code
QRcode::png($your_text, $filename, $errorCorrectionLevel, $matrixPointSize, 2);

// Step 2: Make background transparent
$image = imagecreatefrompng($filename);
$white = imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $white);
imagepng($image, $filename);
imagedestroy($image);

// Show success message
echo "✅ QR code saved successfully: " . basename($filename);

// (Optional) Display the QR image
echo "<br><img src='saved_qrcodes/" . basename($filename) . "' alt='Generated QR Code'>";
?>
