前言
这里使用 simple-qrcode包生成二维码,我在Laravel框架中使用 github: https://github.com/SimpleSoftwareIO/simple-qrcode 安装 composer require simplesoftwareio/simple-qrcode “~2”
- ~2 代表安装v2版本
- ~3 需要安装 imagick 扩展
创建二维码
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Core\CoreController;
use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class IndexController extends CoreController
{
public function index(Request $request)
{
QrCode::format('png')->size(200)->generate('https://github.com',public_path('image/qr_code.png'));
}
}
设置二维码中间的图像
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Core\CoreController;
use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class IndexController extends CoreController
{
public function index(Request $request)
{
$byte = QrCode::format('png')->size(520)->mergeString(file_get_contents(public_path('image/avatar.png')), 0.1)->generate('https://github.com');
return response()->make($byte)->header('content-type', 'image/png');
}
}
结果
|