Laravel使用PHPQRCODE產生帶有LOGO的二維碼圖片

來源:互聯網
上載者:User
本文主要和大家介紹Laravel使用PHPQRCODE實現產生帶有LOGO的二維碼圖片功能,涉及php引入PHPQRCODE類產生二維碼圖片的相關調用與設定作業技巧,需要的朋友可以參考下,希望能協助到大家。


/*** 利用phpqrcode來實現產生帶有logo的二維碼圖片*/public function getQrCode(Request $request){    $type  =  $request->input('type');//傳遞的類型 ios | android    require_once(dirname(__FILE__) . '/phpqrcode/' . 'phpqrcode.php');    $errorCorrectionLevel = 'H'; // 錯誤校正    $matrixPointSize = 5; // 邊界空白位置    $QRcode =  new \QRcode;    if($type){      if($type == 'ios'){        $value =  'http://www.ios.com'; // 二維碼存放的內容        $QRcode->png($value, 'ios.png', $errorCorrectionLevel, $matrixPointSize, 2); //產生二維碼        //echo "二維碼已產生";        $logo = 'logo.png';//logo的圖片地址        //echo " <img src='../../../public/logo.png'>";        $QR = 'ios.png'; //二維碼圖片地址        //echo " <img src='../../../ios.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_height = imagesy($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,'ios.png'); //跟logo合并之後的地址        $a   =  'http://www.ios.com/ios.png';        $status =  0;        $msg  =  $a;      }elseif($type == 'android'){          $value =  'http://www.android.com'; // 二維碼存放的內容          //var_dump($value);          $QRcode->png($value, 'android.png', $errorCorrectionLevel, $matrixPointSize, 2); //產生二維碼          //echo "二維碼已產生";          $logo = 'logo.png';//logo的圖片地址          //echo " <img src='../../../public/logo.png'>";          $QR = 'android.png'; //二維碼圖片地址          //echo " <img src='../../../android.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_height = imagesy($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,'android.png'); //跟logo合并之後的地址          $a   =  'http://www.android.com/android.png';          $status =  0;          $msg  =  $a;      }else{        $status =  1;        $msg  =  '沒有該類型!';      }      //QRcode::png($value, 'sunny.png', $errorCorrectionLevel, $matrixPointSize, 2); //產生二維碼    }else{      $status =  2;      $msg  =  '參數傳遞不完整!';    }    return response()->json(['status' => $status,'msg' => $msg])->header('Access-Control-Allow-Origin', '*');}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.