PHP code example of hao / qrcode

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

    

hao / qrcode example snippets


// 远程图片
$url = 'http://xxx.com/images/2020/09/16013871254283.jpeg';

// 本地图片
$url = ROOT_PATH . 'public/image/logo.png';
$config = array(
    'ecc' => 'H',    // L-smallest, M, Q, H-best
    'size' => 12,    // 1-50
    'dest_file' => ROOT_PATH . 'public/image/qrcode2.png',
    'quality' => 90,
    'logo' => $url,
    'logo_size' => 100,
    'logo_outline_size' => 15,
    'logo_outline_color' => '#FFFFFF',
    'logo_radius' => 10,
    'logo_opacity' => 100,
);

// 二维码内容
$data = 'http://www.baidu.com';

// 创建二维码类
$oPHPQRCode = new \qrcode\PhpQrCode();

// 设定配置
$oPHPQRCode->set_config($config);

// 创建二维码
$qrcode = $oPHPQRCode->generate($data);

$config = array(
    'ecc' => 'H',    // L-smallest, M, Q, H-best
    'size' => 12,    // 1-50
    'dest_file' => ROOT_PATH . 'public/image/qrcode2.png',
    'quality' => 90,
    'logo' => '',
    'logo_size' => null,
    'logo_outline_size' => null,
    'logo_outline_color' => '#FFFFFF',
    'logo_radius' => 100,
    'logo_opacity' => 0,
);

// 二维码内容
$data = 'http://www.baidu.com';

// 创建二维码类
$oPHPQRCode = new \qrcode\PhpQrCode();

// 设定配置
$oPHPQRCode->set_config($config);

// 创建二维码
$qrcode = $oPHPQRCode->generate($data);