<?php //生成二維碼 require_once IA_ROOT . '/framework/library/qrcode/phpqrcode.php'; QRcode::png($url, $qrcode_file, QR_ECLEVEL_L, 4); 注: $url:二維碼內容 $qrcode_file:二維碼存放路徑 //生成的二維碼,添加水印 $font = "/var/www/swoole/ttf/msyh.ttf";//必須絕對路徑 $file = 'image/2.png'; $info = getimagesize($file); // 獲取圖片信息 $type = image_type_to_extension($info[2],false); // 獲取圖片擴展名 $fun = "imagecreatefrom{$type}"; // 構建處理圖片方法名-關鍵是這里 $img = $fun($file); // 調用方法處理 $red = imagecolorallocate($img, 255, 0, 0); $sting = '添加水印'; imagettftext($img, 10, 0, 30, 80, $red, $font, $sting); imagepng($QR, $file); header("Content-type: image/gif; charset=utf-8"); imagegif($img); // 讓生成的二維碼中間帶logo $logo = 'logo.jpg'; $QR = 'image/2.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, 'image/2.png');
