PHP code example of chapdel / qr-code

1. Go to this page and download the library: Download chapdel/qr-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chapdel / qr-code example snippets


use Chapdel\Qr\QRCodeStyling;

$qr = new QRCodeStyling([
    'data' => 'https://example.com',
    'image' => 'https://link-to-your-logo.com/logo.png',
    'dotsOptions' => [
        'type' => 'rounded',
        'color' => '#4267b2'
    ],
    'backgroundOptions' => [
        'color' => '#ffffff',
    ]
]);

// Output SVG
header('Content-Type: image/svg+xml');
echo $qr->getRawData('svg');

$qr = new QRCodeStyling([
    'data' => 'https://example.com',
    'dotsOptions' => [
        'type' => 'classy-rounded',
        'gradient' => [
            'type' => 'linear',
            'rotation' => 45,
            'colorStops' => [
                ['offset' => 0, 'color' => '#ff0000'],
                ['offset' => 1, 'color' => '#0000ff']
            ]
        ]
    ],
    'cornersSquareOptions' => [
        'type' => 'extra-rounded', 
        'color' => '#000000'
    ]
]);

use Chapdel\Qr\Helper\QRContent;

$wifiData = QRContent::wifi('MyHomeNetwork', 'SecretPassword', 'WPA');
// WIFI:T:WPA;S:MyHomeNetwork;P:SecretPassword;;

$qr->update(['data' => $wifiData]);

$qr->applyTheme('facebook'); 
// Automatically sets colors, logo, and shapes to match Facebook branding.

$qr->applyTheme('dark-neon'); 
// Sets a dark background with neon gradients.

$qr->update([
    'dotsOptions' => [
        'type' => 'custom',
        'renderer' => function($x, $y, $size, $color) {
            // Draw a star, heart, or specific icon
            return '<path d="..." fill="'.$color.'"/>';
        }
    ]
]);

$gifBinary = $qr->getRawData('gif');
file_put_contents('animated_qr.gif', $gifBinary);