Handle QR code results
mainOnce a QR code is generated, the $result object allows you to output it in several ways:
- Direct Output: Send the raw string to the browser with the correct MIME type.
- Save to File: Write the image directly to the filesystem.
- Data URI: Generate a base64 encoded string for inline use in
<img>tags.
// Directly output the QR code
header('Content-Type: '.$result->getMimeType());
echo $result->getString();
// Save it to a file
$result->saveToFile(__DIR__.'/qrcode.png');
// Generate a data URI to include image data inline (i.e. inside an <img> tag)
$dataUri = $result->getDataUri();