美文网首页php知识总结
PHP   二维码生成,简单粗暴

PHP   二维码生成,简单粗暴

作者: 响呼雷 | 来源:发表于2016-12-20 12:32 被阅读54次

    在此之前,你要准备一些材料,首先,在网上下载phpqrocode文件,其次就是准备一张放在二维码中心的图片和一个有效的网址,当然,图片和网址是可以随意更改的,这样就ok了。代码都写了注释,希望可以帮到你include 'phpqrcode/phpqrcode.php';

    //二维码内容

    $values = 'http://xh829.com/';

    //容错级别

    $errorCorrectionLevel = 'L';

    //生成图片大小

    $matrixPoinSize = 6;

    //生成二维码图片

    QRcode::png($values,'qrcode.png',$errorCorrectionLevel,$matrixPoinSize,2);

    //准备好的图片

    $logo = '1.png';

    //已经生成的原始二维码图

    $QR = 'qrcode.png';

    if ($logo !== FALSE) {

       $QR = imagecreatefromstring(file_get_contents($QR));

       $logo = imagecreatefromstring(file_get_contents($logo));

       $QR_width = imagesx($QR);//二维码图片宽度

       $QR_height = imagesy($QR);//二维码图片高度

       $logo_width = imagesx($logo);//logo图片宽度

       $logo_height = imagesy($logo);//logo图片高度

       $logo_qr_width = $QR_width / 5;

       $scale = $logo_width/$logo_qr_width;

       $logo_qr_height = $logo_height/$scale;

       $from_width = ($QR_width - $logo_qr_width) / 2;

       //重新组合图片并调整大小

       imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,

           $logo_qr_height, $logo_width, $logo_height);

    }

    //输出图片

    imagepng($QR, 'helloweba.png');

    echo ‘<img   src="helloweba.png">’

    ?>

    相关文章

      网友评论

        本文标题:PHP   二维码生成,简单粗暴

        本文链接:https://www.haomeiwen.com/subject/evwxvttx.html