No description
Find a file
Vincenzo Greco 77064f5e5e Refactor/core ()
* Split core lib into multiple files

* Refactor data encoding methods

* Refactor data masking process

* Improve qr code generation process

* Increase minimum required node version to 0.10

* Add linter

* Add tests and tests coverage

* Update travis config to fix compilation issues

* Add examples folder

* Add missing license tag in package.json

* Update build script and add sourcemap support

* Publish only strictly needed files on npm

* Update readme
2016-12-16 23:45:08 +01:00
bin Refactor/core () 2016-12-16 23:45:08 +01:00
examples Refactor/core () 2016-12-16 23:45:08 +01:00
lib Refactor/core () 2016-12-16 23:45:08 +01:00
test Refactor/core () 2016-12-16 23:45:08 +01:00
.gitignore Refactor/core () 2016-12-16 23:45:08 +01:00
.travis.yml Refactor/core () 2016-12-16 23:45:08 +01:00
build.js Refactor/core () 2016-12-16 23:45:08 +01:00
CONTRIBUTING.md adding contributing guidelines. bump v0.3.0 2015-08-02 05:26:51 -07:00
license adding license. 2015-08-03 11:55:17 -07:00
package.json Refactor/core () 2016-12-16 23:45:08 +01:00
README.md Refactor/core () 2016-12-16 23:45:08 +01:00
test.js Refactor/core () 2016-12-16 23:45:08 +01:00

Travis npm npm npm

node-qrcode

QR code/2d barcode generator.

It is an extension of "QRCode for JavaScript" which Kazuhiko Arase thankfully MIT licensed.

Installation

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

Dependencies

node-canvas is required.
(note: this dependency is only needed for server side use and will be likely removed in the future)

Install node-canvas dependencies

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.

Usage

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.

Example

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

Client side

node-qrcode can be used in browser through Browserify, Webpack or by including the precompiled bundle present in build/ folder.

Browserify or Webpack

<!-- 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!');
})

Precompiled bundle

<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

Methods

draw(canvasElement, text, [optional options], cb(error, canvas));
Options
errorCorrectLevel

Can be one of the values in QRCode.errorCorrectLevel.
If undefined, defaults to H which is max error correction.

Server side API

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. =)

Options
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.

Example

var QRCode = require('qrcode')

QRCode.toDataURL('I am a pony!', function (err, url) {
  console.log(url)
})

GS1 QR Codes

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.

https://github.com/soldair/node-qrcode/issues/45

License

MIT

The word "QR Code" is registered trademark of:
DENSO WAVE INCORPORATED