zoukankan      html  css  js  c++  java
  • QR编码加logo

    <?php
    /**
     * QR Code + Logo Generator
     *
     * http://labs.nticompassinc.com
     */
    $data = isset($_GET['data']) ? $_GET['data'] : 'http://labs.nticompassinc.com';
    $size = isset($_GET['size']) ? $_GET['size'] : '200x200';
    $logo = isset($_GET['logo']) ? $_GET['logo'] : FALSE;
     
    header('Content-type: image/png');
    // Get QR Code image from Google Chart API
    // http://code.google.com/apis/chart/infographics/docs/qr_codes.html
    $QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs='.$size.'&chl='.urlencode($data));
    if($logo !== FALSE){
        $logo = imagecreatefromstring(file_get_contents($logo));
     
        $QR_width = imagesx($QR);
        $QR_height = imagesy($QR);
        
        $logo_width = imagesx($logo);
        $logo_height = imagesy($logo);
        
        // Scale logo to fit in the QR Code
        $logo_qr_width = $QR_width/3;
        $scale = $logo_width/$logo_qr_width;
        $logo_qr_height = $logo_height/$scale;
        
        imagecopyresampled($QR, $logo, $QR_width/3, $QR_height/3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
    }
    imagepng($QR);
    imagedestroy($QR);
    ?>

    下面是我改造的代码(丑陋)

    qr图片和logo生成好了的

                $QR = imagecreatefrompng($qrImage);
                if($logo !== FALSE){
                    $logo = imagecreatefromstring(file_get_contents($logo));
                 
                    $QR_width = imagesx($QR);
                    $QR_height = imagesy($QR);
                    
                    $logo_width = imagesx($logo);
                    $logo_height = imagesy($logo);
                    
                    $logo_qr_width = $QR_width/3;
                    $scale = $logo_width/$logo_qr_width;
                    $logo_qr_height = $logo_height/$scale;
                    
                    imagecopyresampled($QR, $logo, $QR_width/3, $QR_height/3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
                }
                imagepng($QR,$qrImage);
                imagedestroy($QR);
                Cache::write('logoImagePath',$qrImage);
                $this->set('url','/Tools/logoImageFile');
     $logo = imagecreatefromstring(file_get_contents($logo)); 最简单的一个打开图片。
  • 相关阅读:
    donet core 2.1 DateTime ToString() 方法 在不同平台返回的时间格式不一样?
    asp.net core 2.1 post 无法提交参数?
    重写$.ajax方法
    基于git 客户端使用shell工具
    NPOI 自定义单元格背景颜色-Excel
    Ubuntu 1604配置安装mysql8.0
    Fiddler拦截并修改移动端请求
    MFC路径层的使用(BeginPath和EndPath函数)
    MFC中设备描述表dc的使用
    不能从const char *转换为LPCWSTR --VS经常碰到
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/2989684.html
Copyright © 2011-2022 走看看