javascript 如何在没有画布的情况下在 Node.js 中生成 QR 图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29067450/
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
How can I generate QR images in Node.js without canvas?
提问by CherryNerd
I'm building a website for a client in Node.js and I need to generate QR-codes or Barcodes for the ticket system.
我正在用 Node.js 为客户建立一个网站,我需要为票务系统生成二维码或条形码。
I've found a few modules, but all of them need an install like canvas, one way or another.
我找到了一些模块,但它们都需要像画布这样的安装,以一种或另一种方式。
I'm on a shared hosting package and my host does not allow me to install any such packages, unless I upgrade to a VPS or dedicated server (which I do not have the money for).
我在共享主机包上,我的主机不允许我安装任何此类包,除非我升级到 VPS 或专用服务器(我没有钱)。
Does any of you know how I can pull this off in Node.js or do I need to put up a subdomain for generating the QR in PHP or front-end generating (which I do not prefer AT ALL)?
你们有没有人知道我如何在 Node.js 中实现这一点,或者我是否需要建立一个子域来在 PHP 或前端生成中生成 QR(我根本不喜欢)?
Currently using:
目前使用:
- Node.js
- Express.js
- Angular.js
- 节点.js
- Express.js
- Angular.js
Modules found:
找到的模块:
回答by Balaji L
Have a look over this code:
看看这段代码:
var qr = require('qr-image');
var express = require('express');
var app = express();
app.get('/', function(req, res) {
var code = qr.image(new Date().toString(), { type: 'svg' });
res.type('svg');
code.pipe(res);
});
app.listen(3000);
visit npm-qr-image
访问 npm-qr-image
回答by Luscus
回答by Renish Gotecha
回答by hamedkke
try it
试试看
1)npm i qrcode
2)var QRCode = require('qrcode')
3)QRCode.toString('I am a pony!',{type:'terminal'}, function (err,
base64image) {
console.log(base64image)
})