Giter Site home page Giter Site logo

node-qrcode's Introduction

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.

soldair#45

License

MIT

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

node-qrcode's People

Contributors

soldair avatar fatelei avatar wemakeweb avatar vigreco avatar aldonline avatar jvanaert avatar joemccann avatar heartnetkung avatar ryohey avatar supericeboy avatar throrin19 avatar daawesomep avatar drewp avatar blakmatrix avatar nathanoehlman avatar spro avatar thinkroth avatar freewil avatar dannysu09 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.