Laravel 中的二维码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37825742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:59:24  来源:igfitidea点击:

Qrcode in laravel

laravellaravel-5laravel-5.1laravel-5.2qr-code

提问by Adam Projo

i want to make qrcode, in there i can make it but i have something trouble when i want to change the format of qrcode to png file. but its only show symbol

我想制作二维码,在那里我可以制作,但是当我想将二维码的格式更改为 png 文件时遇到了一些麻烦。但它唯一的显示符号

here my view :

我的观点是:

<?php echo QrCode::size(265)->generate($row->id) ?>

this qrcode i use :

我使用的这个二维码:

"simplesoftwareio/simple-qrcode": "~1"

here my referance : https://www.simplesoftware.io/docs/simple-qrcode

这是我的参考:https: //www.simplesoftware.io/docs/simple-qrcode

can anyone help me ? or can someone give me solution ? before i change format to png : this before i change format

谁能帮我 ?或者有人可以给我解决方案吗?在我将格式更改为 png 之前: 这是在我更改格式之前

and this after i change it : after i change it

在我改变它之后: 在我改变之后

回答by nasirkhan

There are more simple example available as well.

还有更简单的例子可用。

<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!} ">

回答by SteD

If you are formatting it as png file format, you need to include it with a <img>tag.

如果要将其格式化为 png 文件格式,则需要将其包含在<img>标签中。

Taken from the documentation

取自文档

//Inside of a blade template.
<img src="{!!$message->embedData(QrCode::format('png')->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png')!!}">

You can also do this:

你也可以这样做:

$png = QrCode::format('png')->size(512)->generate(1);
$png = base64_encode($png);
echo "<img src='data:image/png;base64," . $png . "'>";

回答by Arati

In controller

在控制器中

$path = getenv('IMAGE_URL')."/img/logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);

In blade file

在刀片文件中

<img src='data:image/png;base64,{{$png}}'>