1. 程式人生 > >PHP生成二維碼與識別二維碼

PHP生成二維碼與識別二維碼

<?php /** * Created by PhpStorm. * User: user * Date: 2018/8/16 * Time: 10:43 */ include "./qrcode/phpqrcode.php"; $txt = "測試內容"; $picPathAndName = "./pic/ABC.jpg";//二維碼儲存路徑和名稱 $level = 'L'; $size = 5; $is_logo = 1;//是否包含Logo 0否 1是 $margin = 2;//邊距 $saveAndPrint = true;//是否儲存,儲存時,$picPathAndName設定為true //生成二維碼圖片QRcode::png($txt, $picPathAndName, $level, $size, $margin,$saveAndPrint);
if($is_logo == 1){ $QR = $picPathAndName; //已經生成的原始二維碼圖 $Logo = './pic/logo.png'; $Logo_re = './pic/test_logo.png'; $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, $Logo_re); }