Header Ads Widget

How to create a simple QR code generator using PHP

How you can create a QR code in PHP using the endroid/qr-code library:


< ?php

// Include the library
require_once '/path/to/vendor/autoload.php';

use Endroid\QrCode\QrCode;

// Set the text to encode
$text = 'This is the text I want to encode';

// Create a new QR code
$qrCode = new QrCode($text);

// Set the size of the QR code
$qrCode->setSize(300);

// Set the foreground color
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);

// Set the background color
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);

// Output the QR code as an image
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();


This code will generate a 300x300 pixel QR code with black foreground and white background colors. The QR code will contain the text This is the text I want to encode.

Post a Comment

0 Comments