This script uses the PHP library “Endroid/QrCode” to generate a QR code. The QR code’s content is specified in the $qr_content
variable, and the size of the QR code can be set using the $qr_size
variable. The QR code image is then outputted as a string, which can be saved to a file or displayed on a webpage.
You need to install Endroid/qr-code library using composer by running ‘composer require endroid/qr-code’ before using it.
<?php
// Required library
require 'vendor/autoload.php';
// QR code content
$qr_content = 'https://www.example.com';
// QR code size
$qr_size = 300;
// Create a QR code instance
$qr_code = new Endroid\QrCode\QrCode($qr_content);
// Set size
$qr_code->setSize($qr_size);
// Create the QR code image
header('Content-Type: '.$qr_code->getContentType());
echo $qr_code->writeString();