我正在尝试在我的网站上生成二维码。他们所要做的就是在他们里面有一个URL,我的网站上的一个变量将提供这个URL。做这件事最简单的方法是什么?
发布于 2011-05-10 06:49:28
用PHP生成二维码最简单的方法是phpqrcode library。
发布于 2014-01-11 23:46:41
API库的配置速度非常快,而且文档也很容易理解。
除了abaumg的回答之外,我还附上了两个来自http://phpqrcode.sourceforge.net/examples/index.php的PHP示例
1.二维码编码器
首先包含本地路径中的库
include('../qrlib.php');然后将图像直接输出为PNG流,例如:
QRcode::png('your texte here...');要将结果本地保存为PNG图像,请执行以下操作:
$tempDir = EXAMPLE_TMP_SERVERPATH;
$codeContents = 'your message here...';
$fileName = 'qrcode_name.png';
$pngAbsoluteFilePath = $tempDir.$fileName;
$urlRelativeFilePath = EXAMPLE_TMP_URLRELPATH.$fileName;
QRcode::png($codeContents, $pngAbsoluteFilePath); 2. QR码解码器
另请参阅zxing解码器:
http://zxing.org/w/decode.jspx
检查输出非常有用。
3.数据格式列表
根据数据类型,您可以在二维码中使用的数据格式列表:
视频网站网址:http://)
http://)
:smsto:number:message
发布于 2016-11-23 20:16:56
endroid/QrCode library易于使用、维护良好,并且可以使用composer进行安装。还有一个可以直接与Symfony一起使用的bundle。
安装:
$ composer require endroid/qrcode用法:
<?php
use Endroid\QrCode\QrCode;
$qrCode = new QrCode();
$qrCode
->setText('Life is too short to be generating QR codes')
->setSize(300)
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
->setLabel('Scan the code')
->setLabelFontSize(16)
->setImageType(QrCode::IMAGE_TYPE_PNG)
;
// now we can directly output the qrcode
header('Content-Type: '.$qrCode->getContentType());
$qrCode->render();
// or create a response object
$response = new Response($qrCode->get(), 200, array('Content-Type' => $qrCode->getContentType()));

https://stackoverflow.com/questions/5943368
复制相似问题