Génération de QRCode Laravel

De Gandal
Révision datée du 11 juin 2024 à 15:52 par Abdoulaye (discussion | contributions)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Version plus complète : https://github.com/endroid/qr-code

SimpleSoftwareIO/simple-qrcode: An easy-to-use PHP QrCode generator with first-party support for Laravel. (github.com)

<?php
/* Un exemple*/
private function generateQrCode($text)
    {
        $result = Builder::create()
            ->writer(new PngWriter())
            ->writerOptions([])
            ->data($text)
            ->encoding(new Encoding('UTF-8'))
            ->errorCorrectionLevel(ErrorCorrectionLevel::High)
            ->size(300)
            ->margin(10)
            ->roundBlockSizeMode(RoundBlockSizeMode::Margin)
            ->foregroundColor(new Color(0, 0, 0))
            ->backgroundColor(new Color(255, 255, 255))
            ->logoPath("https://www.mouleagaufres.com/wp-content/uploads/2022/03/logoMAG-blanc.png")
            ->logoResizeToWidth(50)
            ->logoPunchoutBackground(true)
            ->validateResult(false)
            ->build();

        return $result->getString();
    }