Skip to content

QR Codes

Đorđe Jocić edited this page Dec 5, 2026 · 6 revisions

QR Code generation was changed in the 1.1.x version and is now done through the QrCode wrapper that utilizes one of many available encoders.

Importing Namespace

use Jocic\GoogleAuthenticator\Secret;
use Jocic\GoogleAuthenticator\Account;
use Jocic\GoogleAuthenticator\Encoder;
use Jocic\GoogleAuthenticator\QrCode;

use Jocic\GoogleAuthenticator\Encoders\Endroid;

Creating a Test Account

$account = new Account();

$account->setService("My Service");
$account->setIdentifier("john@doe.com");
$account->setSecret("RMB4AMUMDHODBYNR");

Encoder Setup

$encoder = new Endroid();

$encoder->setSize(200);
$encoder->setMargin(5);
$encoder->setBackgroundColor("#ffffff");
$encoder->setForegroundColor("#000000");
$encoder->setFormat(Encoder::FORMAT_PNG);
$encoder->setErrorCorrection(Encoder::ECC_LOW);

QR Code Generation

$qrCode = new QrCode();

$qrCode->setDirectory("/path/to/my/storage");
$qrCode->setFilename("my-code.png");
$qrCode->setEncoder($encoder);
            
if ($qrCode->generate($account)) {
    echo $encoder->getEmbeddable();
}

Clone this wiki locally