This article mainly introduces nodejs to achieve a super simple method of generating QR codes, and analyzes the related operating skills of nodejs based on the qr-image plug-in to generate QR codes in the form of examples. Friends who need it can refer to it and use it at the beginning. node-qrcode(https://github.com/soldair/node-qrcode),As a result, you need to install python when installing, and it does not support python3.0 or above. You need to install it when installing python2.0 Other environments, so I gave up.
Finally chose a niche plug-inqr-image(https://github.com/alexeyten/qr-image)
The front page is as follows
views/index.ejs
<!DOCTYPE html> <html> <head> <title><%= title %></title> <link rel='stylesheet' href='/stylesheets/style.css'/> </head> <body> <h1><%= title %></h1> <img src="/create_qrcode?text=http://blog.csdn.net/fo11ower"/> </body> </html>
Backend code:
routes/index. js
var qr = require('qr-image') router.get('/', function (req, res, next) { res.render('index', {title: 'Express'}); }); router.get('/create_qrcode', function (req, res, next) { var text = req.query.text; try { var img = qr.image(text,{size :10}); res.writeHead(200, {'Content-Type': 'image/png'}); img.pipe(res); } catch (e) { res.writeHead(414, {'Content-Type': 'text/html'}); res.end('<h1>414 Request-URI Too Large</h1>'); } })
Related recommendations:
JS method to generate a QR code from a link and convert it into an image
phpqrcode class generates QR code method
The above is the detailed content of Nodejs super simple method to generate QR code. For more information, please follow other related articles on the PHP Chinese website!