QR code/2d barcode generator.
It is an extension of "QRCode for JavaScript" which Kazuhiko Arase thankfully MIT licensed.
Inside your project folder do:
npm install --save qrcode
or, install it globally to use qrcode
from the command line to save qrcode images or generate ones you can view in your terminal.
npm install -g qrcode
node-canvas
is required.
(note: this dependency is only needed for server side use and will be likely removed in the future)
node-canvas
is a native module and requires dev packages of Cairo
and Pango
to compile.
Make sure to have these libs available on your system before run npm install qrcode
Installation instructions are available on node-canvas page.
qrcode <text> [output file]
Output image format is detected from file extension.
Only png
and svg
format are supported for now.
If no output file is specified, the QR Code will be rendered directly in the terminal.
qrcode "Draw a QR Code in my terminal"
qrcode "I like to save qrs as a PNG" qr.png
qrcode "I also like to save them as a SVG" qr.svg
node-qrcode
can be used in browser through Browserify, Webpack or by including the precompiled
bundle present in build/
folder.
<!-- index.html -->
<html>
<body>
<canvas id="canvas"></canvas>
<script src="bundle.js"></script>
</body>
</html>
// index.js -> bundle.js
var QRCode = require('qrcode')
var QRCodeDraw = new QRCode.QRCodeDraw()
var canvas = document.getElementById('canvas')
QRCodeDraw.draw(canvas, 'sample text', function (error, canvas) {
if (error) console.error(error)
console.log('success!');
})
<canvas id="canvas"></canvas>
<script src="/build/qrcode.min.js"></script>
<script>
var qrcodedraw = new qrcodelib.qrcodedraw()
qrcodedraw.draw(document.getElementById('canvas'), 'sample text', function (error, canvas) {
if (error) console.error(error)
console.log('success!');
})
</script>
Precompiled files are generated in build/
folder during installation.
To manually rebuild the lib run:
npm run build
draw(canvasElement, text, [optional options], cb(error, canvas));
errorCorrectLevel
Can be one of the values in QRCode.errorCorrectLevel
.
If undefined
, defaults to H which is max error correction.
QRCode.draw(text, [optional options], cb(error, canvas));
Returns a node canvas object see https://github.com/Automattic/node-canvas for all of the cool node things you can do. Look up the canvas api for the other cool things.
QRCode.toDataURL(text, [optional options], cb(error, dataURL));
Returns mime image/png data url for the 2d barcode.
QRCode.drawSvg(text, [optional options], cb(error, svgString));
SVG output!
QRCode.save(path, text, [optional options], cb(error, written));
Saves png to the path specified returns bytes written.
QRCode.drawText(text, [optional options], cb)
Returns an ascii representation of the qrcode using unicode characters and ansi control codes for background control.
QRCode.drawBitArray(text, [optional options], cb(error, bits, width));
Returns an array with each value being either 0 light or 1 dark and the width of each row. This is enough info to render a qrcode any way you want. =)
errorCorrectLevel
Can be one of the values in qrcode.errorCorrectLevel
.
Can be a string, one of "minimum", "medium", "high", "max"
.
If undefined
, defaults to H which is max error correction.
var QRCode = require('qrcode')
QRCode.toDataURL('I am a pony!', function (err, url) {
console.log(url)
})
There was a real good discussion here about them. but in short any qrcode generator will make gs1 compatable qrcodes, but what defines a gs1 qrcode is a header with metadata that describes your gs1 information.
The word "QR Code" is registered trademark of:
DENSO WAVE INCORPORATED