<?php
require_once 'vendor/autoload.php';
require_once 'config/db.php';

use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;

if (!isset($_GET['barcode'])) {
    header('Content-Type: application/json');
    echo json_encode(['error' => 'No barcode provided']);
    exit();
}

$barcode = $_GET['barcode'];

// Create QR code options
$options = new QROptions([
    'eccLevel' => QRCode::ECC_L,
    'outputType' => QRCode::OUTPUT_IMAGE_PNG,
    'version' => 5,
]);

// Create QR code instance
$qrcode = new QRCode($options);

// Set headers for image output
header('Content-Type: image/png');

// Output the QR code
echo $qrcode->render($barcode);
