PHP code example of amirezaeb / heroqr

1. Go to this page and download the library: Download amirezaeb/heroqr 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/ */

    

amirezaeb / heroqr example snippets



use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set the data to be encoded in the QR code
    ->setData('https://test.org') 
    # Generate the QR code in PNG format (default)
    ->generate();

# Save the generated QR code to a file named 'qrcode.png'
$qrCode->saveTo('qrcode'); 



use HeroQR\Core\QRCodeGenerator;
use HeroQR\DataTypes\DataType;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set data to be encoded and validate it as an Email
    ->setData('[email protected]', DataType::Email)  
    # Set background and QR code colors
    ->setBackgroundColor('#ffffffFF')
    # Set the QR code's color
    ->setColor('#fc031c')
    # Set the size of the QR code (default size is 800)
    ->setSize(900)
    # Set the logo to be embedded at the center (default size is 80)
    ->setLogo('../assets/HeroExpert.png', 100 )
    # Set the margin around the QR code (default size is 10)
    ->setMargin(20)
    # Set character encoding for the QR code (default encoding is UTF-8)
    ->setEncoding('CP866')
    # Customize the label with text, alignment, color, and font size
    ->setLabel(
        # Label Text
        label: 'To Contact Me, Just Scan This QRCode',
        # Label align (default: center)
        textAlign: 'right',
        # Label text color (default: #000000)
        textColor: '#fc031c',
        # Label size (default: 50)
        fontSize: 35,
        # Label margin (default: 0, 10, 10, 10)
        margin: [15, 15, 15, 15] 
    )
    # Generate the QR code in WebP format
    ->generate('webp');

# Save the generated QR code to a file
$qrCode->saveTo('custom-qrcode');



use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    ->setData('https://example.com')
    ->setSize(800)
    ->setBackgroundColor('#ffffffFF')
    ->setColor('#000000')
    # Customize the Shape (S2), Marker (M2), and Cursor (C2)
    ->generate('png',[
            'Shape' => 'S2',
            'Marker' => 'M2',
            'Cursor' => 'C2'
        ]);

# Save the generated QR code with customizations
$qrCode->saveTo('custom-qr');



use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set the data to be encoded in the QR code
    ->setData('https://test.org') 
    # Generate the QR code in PNG format (default)
    ->generate();

# Get the QR code as a string representation
$string = $qrCode->getString();

# Get the QR code as a matrix object
$matrix = $qrCode->getMatrix();

# Get the matrix as a 2D array
$matrixArray = $qrCode->getMatrixAsArray();

# Get the QR code as Base64 encoding for embedding in HTML
$dataUri = $qrCode->getDataUri();

# Save the QR code to a file in the desired format (WebP, GIF, Binary, Esp, PNG, SVG, PDF)
$qrCode->saveTo('qr_code_output');