qrcode vs uqr vs qr.js vs react-qr-code vs qrious vs qr-image
QR Code Generation
qrcodeuqrqr.jsreact-qr-codeqriousqr-imageSimilar Packages:
QR Code Generation

QR Code Generation libraries in JavaScript provide tools for creating Quick Response (QR) codes, which are two-dimensional barcodes that can store information such as URLs, text, or contact details. These libraries allow developers to generate QR codes programmatically, customize their appearance, and integrate them into web applications, mobile apps, or print media. They often support features like error correction, different encoding formats, and the ability to generate QR codes in various sizes and styles. QR code generation is useful for applications like digital marketing, event ticketing, contactless payments, and information sharing.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
qrcode6,566,5608,055135 kB1142 years agoMIT
uqr1,888,07469272 kB13 years agoMIT
qr.js1,309,598---13 years agoMIT
react-qr-code1,223,83786513.8 kB137 months agoMIT
qrious64,5961,623-439 years agoGPL-3.0
qr-image01,063-159 years agoMIT
Feature Comparison: qrcode vs uqr vs qr.js vs react-qr-code vs qrious vs qr-image

Output Formats

  • qrcode:

    qrcode supports multiple output formats, including PNG, SVG, and canvas, providing flexibility for both web and mobile applications.

  • uqr:

    uqr supports multiple output formats, including SVG, PNG, and canvas, making it versatile for both web and print applications.

  • qr.js:

    qr.js generates QR codes as canvas elements or SVG, allowing for high-quality, scalable output suitable for web applications and graphic design.

  • react-qr-code:

    react-qr-code generates QR codes as SVG or canvas elements, allowing for scalable and high-quality output that integrates well with web applications.

  • qrious:

    qrious generates QR codes as canvas elements, which can be easily styled and manipulated in the browser. It does not support SVG or image file output directly.

  • qr-image:

    qr-image supports generating QR codes in PNG, JPEG, and SVG formats, making it versatile for various use cases, including web, print, and digital media.

Customization

  • qrcode:

    qrcode provides a high level of customization, allowing developers to adjust the size, color, error correction level, and even embed images within the QR code, making it suitable for branding and design purposes.

  • uqr:

    uqr offers advanced customization features, including the ability to change colors, sizes, error correction levels, and the option to add logos or images, making it highly flexible for branding.

  • qr.js:

    qr.js offers extensive customization options, including control over the QR code's size, color, error correction level, and the ability to add logos or images within the code.

  • react-qr-code:

    react-qr-code allows customization of QR codes through props, including size, color, and error correction level. It is designed to be easily styled and integrated into React components.

  • qrious:

    qrious allows for some customization, including size, foreground and background colors, and the ability to add a logo, but is relatively simple compared to more feature-rich libraries.

  • qr-image:

    qr-image allows for basic customization of QR codes, including size, error correction level, and color, but is primarily focused on generating codes quickly and efficiently.

Ease of Use

  • qrcode:

    qrcode is easy to use, with clear documentation and examples. Its API is intuitive, making it accessible for both novice and experienced developers.

  • uqr:

    uqr features a clean and modern API that is easy to use. The documentation is comprehensive, making it simple for developers to understand and implement its features.

  • qr.js:

    qr.js has a user-friendly API, especially for developers familiar with JavaScript. Its documentation provides clear examples, making it easy to implement client-side QR code generation.

  • react-qr-code:

    react-qr-code is easy to use for React developers, with a simple component-based API. Its documentation provides examples that make integration straightforward.

  • qrious:

    qrious is designed for simplicity, with a minimalistic API that makes it easy to generate QR codes quickly. The documentation is clear and concise, aiding quick implementation.

  • qr-image:

    qr-image is straightforward to use, with a simple API for generating QR codes quickly. It is well-documented and easy to integrate into Node.js applications.

Code Examples

  • qrcode:

    Generate QR Code with qrcode

    const QRCode = require('qrcode');
    
    // Generate QR code as data URL
    QRCode.toDataURL('Hello, World!', { errorCorrectionLevel: 'H' }, (err, url) => {
        console.log(url);
    });
    
    // Generate QR code as PNG
    QRCode.toFile('qrcode.png', 'Hello, PNG!', { errorCorrectionLevel: 'H' }, (err) => {
        if (err) throw err;
        console.log('QR code saved as PNG.');
    });
    
  • uqr:

    Generate QR Code with uqr

    import { QRCode } from 'uqr';
    
    // Create a QR code instance
    const qrCode = new QRCode('Hello, UQR!', {
        errorCorrectionLevel: 'H',
        size: 200,
        color: { dark: '#000', light: '#fff' },
    });
    
    // Render the QR code
    qrCode.render();
    
  • qr.js:

    Generate QR Code with qr.js

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>QR Code with qr.js</title>
        <script src="path/to/qr.js"></script>
    </head>
    <body>
        <div id="qrcode"></div>
        <script>
            const qr = new QRCode(document.getElementById('qrcode'), {
                text: 'Hello, QR Code!',
                width: 128,
                height: 128,
                colorDark: '#000000',
                colorLight: '#ffffff',
                correctLevel: QRCode.CorrectLevel.H
            });
        </script>
    </body>
    </html>
    
  • react-qr-code:

    Generate QR Code with react-qr-code

    import React from 'react';
    import { QRCode } from 'react-qr-code';
    
    const App = () => {
        return (
            <div>
                <h1>QR Code</h1>
                <QRCode value="Hello, React QR Code!" size={256} />
            </div>
        );
    };
    
    export default App;
    
  • qrious:

    Generate QR Code with qrious

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>QR Code with qrious</title>
        <script src="path/to/qrious.min.js"></script>
    </head>
    <body>
        <canvas id="qr-canvas"></canvas>
        <script>
            const qr = new QRious({
                element: document.getElementById('qr-canvas'),
                value: 'Hello, QRious!',
                size: 200,
                foreground: '#000000',
                background: '#ffffff'
            });
        </script>
    </body>
    </html>
    
  • qr-image:

    Generate QR Code with qr-image

    const qr = require('qr-image');
    const fs = require('fs');
    
    // Generate QR code as PNG
    const code = qr.imageSync('Hello, World!', { type: 'png' });
    fs.writeFileSync('qrcode.png', code);
    
    // Generate QR code as SVG
    const svg = qr.imageSync('Hello, SVG!', { type: 'svg' });
    fs.writeFileSync('qrcode.svg', svg);
    
How to Choose: qrcode vs uqr vs qr.js vs react-qr-code vs qrious vs qr-image
  • qrcode:

    Opt for qrcode if you want a versatile library that supports both server-side and client-side QR code generation. It offers a wide range of features, including customization, error correction, and support for various output formats, making it a great all-around choice for most applications.

  • uqr:

    Choose uqr if you need a modern and feature-rich QR code generator that supports both client-side and server-side generation. It offers a clean API, supports multiple output formats, and provides advanced features like customization and error correction, making it suitable for a wide range of applications.

  • qr.js:

    Select qr.js if you require a pure JavaScript implementation for generating QR codes in the browser. It is highly customizable and allows for detailed control over the QR code generation process, making it suitable for projects that need client-side generation without external dependencies.

  • react-qr-code:

    Select react-qr-code if you are working on a React application and need a component-based solution for generating QR codes. It is designed specifically for React, making it easy to integrate and use within your React projects, with support for props-based customization.

  • qrious:

    Choose qrious if you need a lightweight and easy-to-use library for generating QR codes in the browser. It provides a simple API and supports customization, making it ideal for projects that require quick and straightforward QR code generation without a lot of overhead.

  • qr-image:

    Choose qr-image if you need a simple and efficient solution for generating QR codes as images or SVGs directly on the server side. It is lightweight and easy to integrate into Node.js applications.

README for qrcode

node-qrcode

QR code/2d barcode generator.

Travis npm npm npm

Highlights

  • Works on server and client (and react native with svg)
  • CLI utility
  • Save QR code as image
  • Support for Numeric, Alphanumeric, Kanji and Byte mode
  • Support for mixed modes
  • Support for chinese, cyrillic, greek and japanese characters
  • Support for multibyte characters (like emojis :smile:)
  • Auto generates optimized segments for best data compression and smallest QR Code size
  • App agnostic readability, QR Codes by definition are app agnostic

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

Usage

CLI

Usage: qrcode [options] <input string>

QR Code options:
  -v, --qversion  QR Code symbol version (1 - 40)                       [number]
  -e, --error     Error correction level           [choices: "L", "M", "Q", "H"]
  -m, --mask      Mask pattern (0 - 7)                                  [number]

Renderer options:
  -t, --type        Output type                  [choices: "png", "svg", "utf8"]
  -w, --width       Image width (px)                                    [number]
  -s, --scale       Scale factor                                        [number]
  -q, --qzone       Quiet zone size                                     [number]
  -l, --lightcolor  Light RGBA hex color
  -d, --darkcolor   Dark RGBA hex color
  --small  Output smaller QR code to terminal                          [boolean]

Options:
  -o, --output  Output file
  -h, --help    Show help                                              [boolean]
  --version     Show version number                                    [boolean]

Examples:
  qrcode "some text"                    Draw in terminal window
  qrcode -o out.png "some text"         Save as png image
  qrcode -d F00 -o out.png "some text"  Use red as foreground color

If not specified, output type is guessed from file extension.
Recognized extensions are png, svg and txt.

Browser

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

Module bundlers

<!-- index.html -->
<html>
  <body>
    <canvas id="canvas"></canvas>
    <script src="bundle.js"></script>
  </body>
</html>
// index.js -> bundle.js
var QRCode = require('qrcode')
var canvas = document.getElementById('canvas')

QRCode.toCanvas(canvas, 'sample text', function (error) {
  if (error) console.error(error)
  console.log('success!');
})

Precompiled bundle

<canvas id="canvas"></canvas>

<script src="/build/qrcode.js"></script>
<script>
  QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
    if (error) console.error(error)
    console.log('success!');
  })
</script>

If you install through npm, precompiled files will be available in node_modules/qrcode/build/ folder.

The precompiled bundle have support for Internet Explorer 10+, Safari 5.1+, and all evergreen browsers.

NodeJS

Require the module qrcode

var QRCode = require('qrcode')

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

render a qrcode for the terminal

var QRCode = require('qrcode')

QRCode.toString('I am a pony!',{type:'terminal'}, function (err, url) {
  console.log(url)
})

ES6/ES7

Promises and Async/Await can be used in place of callback function.

import QRCode from 'qrcode'

// With promises
QRCode.toDataURL('I am a pony!')
  .then(url => {
    console.log(url)
  })
  .catch(err => {
    console.error(err)
  })

// With async/await
const generateQR = async text => {
  try {
    console.log(await QRCode.toDataURL(text))
  } catch (err) {
    console.error(err)
  }
}

Error correction level

Error correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged. Four levels are available to choose according to the operating environment.

Higher levels offer a better error resistance but reduce the symbol's capacity.
If the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor) is possible to safely use a low error level such as Low or Medium.

Possible levels are shown below:

LevelError resistance
L (Low)~7%
M (Medium)~15%
Q (Quartile)~25%
H (High)~30%

The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.

Error level can be set through options.errorCorrectionLevel property.
If not specified, the default value is M.

QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, function (err, url) {
  console.log(url)
})

QR Code capacity

Capacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.

The QR Code versions range from version 1 to version 40.
Each version has a different number of modules (black and white dots), which define the symbol's size. For version 1 they are 21x21, for version 2 25x25 e so on. Higher is the version, more are the storable data, and of course bigger will be the QR Code symbol.

The table below shows the maximum number of storable characters in each encoding mode and for each error correction level.

ModeLMQH
Numeric7089559639933057
Alphanumeric4296339124201852
Byte2953233116631273
Kanji181714351024784

Note: Maximum characters number can be different when using Mixed modes.

QR Code version can be set through options.version property.
If no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.

QRCode.toDataURL('some text', { version: 2 }, function (err, url) {
  console.log(url)
})

Encoding modes

Modes can be used to encode a string in a more efficient way.
A mode may be more suitable than others depending on the string content. A list of supported modes are shown in the table below:

ModeCharactersCompression
Numeric0, 1, 2, 3, 4, 5, 6, 7, 8, 93 characters are represented by 10 bits
Alphanumeric0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, :2 characters are represented by 11 bits
KanjiCharacters from the Shift JIS system based on JIS X 02082 kanji are represented by 13 bits
ByteCharacters from the ISO/IEC 8859-1 character setEach characters are represented by 8 bits

Choose the right mode may be tricky if the input text is unknown.
In these cases Byte mode is the best choice since all characters can be encoded with it. (See Multibyte characters)
However, if the QR Code reader supports mixed modes, using Auto mode may produce better results.

Mixed modes

Mixed modes are also possible. A QR code can be generated from a series of segments having different encoding modes to optimize the data compression.
However, switching from a mode to another has a cost which may lead to a worst result if it's not taken into account. See Manual mode for an example of how to specify segments with different encoding modes.

Auto mode

By default, automatic mode selection is used.
The input string is automatically splitted in various segments optimized to produce the shortest possible bitstream using mixed modes.
This is the preferred way to generate the QR Code.

For example, the string ABCDE12345678?A1A will be splitted in 3 segments with the following modes:

SegmentMode
ABCDEAlphanumeric
12345678Numeric
?A1AByte

Any other combinations of segments and modes will result in a longer bitstream.
If you need to keep the QR Code size small, this mode will produce the best results.

Manual mode

If auto mode doesn't work for you or you have specific needs, is also possible to manually specify each segment with the relative mode. In this way no segment optimizations will be applied under the hood.
Segments list can be passed as an array of object:

  var QRCode = require('qrcode')

  var segs = [
    { data: 'ABCDEFG', mode: 'alphanumeric' },
    { data: '0123456', mode: 'numeric' }
  ]

  QRCode.toDataURL(segs, function (err, url) {
    console.log(url)
  })

Kanji mode

With kanji mode is possible to encode characters from the Shift JIS system in an optimized way.
Unfortunately, there isn't a way to calculate a Shifted JIS values from, for example, a character encoded in UTF-8, for this reason a conversion table from the input characters to the SJIS values is needed.
This table is not included by default in the bundle to keep the size as small as possible.

If your application requires kanji support, you will need to pass a function that will take care of converting the input characters to appropriate values.

An helper method is provided by the lib through an optional file that you can include as shown in the example below.

Note: Support for Kanji mode is only needed if you want to benefit of the data compression, otherwise is still possible to encode kanji using Byte mode (See Multibyte characters).

  var QRCode = require('qrcode')
  var toSJIS = require('qrcode/helper/to-sjis')

  QRCode.toDataURL(kanjiString, { toSJISFunc: toSJIS }, function (err, url) {
    console.log(url)
  })

With precompiled bundle:

<canvas id="canvas"></canvas>

<script src="/build/qrcode.min.js"></script>
<script src="/build/qrcode.tosjis.min.js"></script>
<script>
  QRCode.toCanvas(document.getElementById('canvas'),
    'sample text', { toSJISFunc: QRCode.toSJIS }, function (error) {
    if (error) console.error(error)
    console.log('success!')
  })
</script>

Binary data

QR Codes can hold arbitrary byte-based binary data. If you attempt to create a binary QR Code by first converting the data to a JavaScript string, it will fail to encode propery because string encoding adds additional bytes. Instead, you must pass a Uint8ClampedArray or compatible array, or a Node Buffer, as follows:

// Regular array example
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
const QRCode = require('qrcode')
QRCode.toFile(
  'foo.png',
  [{ data: [253,254,255], mode: 'byte' }],
  ...options...,
  ...callback...
)
// Uint8ClampedArray example
const QRCode = require('qrcode')

QRCode.toFile(
  'foo.png',
  [{ data: new Uint8ClampedArray([253,254,255]), mode: 'byte' }],
  ...options...,
  ...callback...
)
// Node Buffer example
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
const QRCode = require('qrcode')

QRCode.toFile(
  'foo.png',
  [{ data: Buffer.from([253,254,255]), mode: 'byte' }],
  ...options...,
  ...callback...
)

TypeScript users: if you are using @types/qrcode, you will need to add a // @ts-ignore above the data segment because it expects data: string.

Multibyte characters

Support for multibyte characters isn't present in the initial QR Code standard, but is possible to encode UTF-8 characters in Byte mode.

QR Codes provide a way to specify a different type of character set through ECI (Extended Channel Interpretation), but it's not fully implemented in this lib yet.

Most QR Code readers, however, are able to recognize multibyte characters even without ECI.

Note that a single Kanji/Kana or Emoji can take up to 4 bytes.

API

Browser:

Server:

Browser API

create(text, [options])

Creates QR Code symbol and returns a qrcode object.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options

See QR Code options.

returns

Type: Object

// QRCode object
{
  modules,              // Bitmatrix class with modules data
  version,              // Calculated QR Code version
  errorCorrectionLevel, // Error Correction Level
  maskPattern,          // Calculated Mask pattern
  segments              // Generated segments
}

toCanvas(canvasElement, text, [options], [cb(error)])

toCanvas(text, [options], [cb(error, canvas)])

Draws qr code symbol to canvas.
If canvasElement is omitted a new canvas is returned.

canvasElement

Type: DOMElement

Canvas where to draw QR Code.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options

See Options.

cb

Type: Function

Callback function called on finish.

Example
QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, function (err, canvas) {
  if (err) throw err

  var container = document.getElementById('container')
  container.appendChild(canvas)
})

toDataURL(text, [options], [cb(error, url)])

toDataURL(canvasElement, text, [options], [cb(error, url)])

Returns a Data URI containing a representation of the QR Code image.
If provided, canvasElement will be used as canvas to generate the data URI.

canvasElement

Type: DOMElement

Canvas where to draw QR Code.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options
  • type

    Type: String
    Default: image/png

    Data URI format.
    Possible values are: image/png, image/jpeg, image/webp.

  • rendererOpts.quality

    Type: Number
    Default: 0.92

    A Number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp.

See Options for other settings.

cb

Type: Function

Callback function called on finish.

Example
var opts = {
  errorCorrectionLevel: 'H',
  type: 'image/jpeg',
  quality: 0.3,
  margin: 1,
  color: {
    dark:"#010599FF",
    light:"#FFBF60FF"
  }
}

QRCode.toDataURL('text', opts, function (err, url) {
  if (err) throw err

  var img = document.getElementById('image')
  img.src = url
})

toString(text, [options], [cb(error, string)])

Returns a string representation of the QR Code.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options
  • type

    Type: String
    Default: utf8

    Output format.
    Possible values are: terminal,utf8, and svg.

See Options for other settings.

cb

Type: Function

Callback function called on finish.

Example
QRCode.toString('http://www.google.com', function (err, string) {
  if (err) throw err
  console.log(string)
})

Server API

create(text, [options])

See create.


toCanvas(canvas, text, [options], [cb(error)])

Draws qr code symbol to node canvas.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options

See Options.

cb

Type: Function

Callback function called on finish.


toDataURL(text, [options], [cb(error, url)])

Returns a Data URI containing a representation of the QR Code image.
Only works with image/png type for now.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options

See Options for other settings.

cb

Type: Function

Callback function called on finish.


toString(text, [options], [cb(error, string)])

Returns a string representation of the QR Code.
If choosen output format is svg it will returns a string containing xml code.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options
  • type

    Type: String
    Default: utf8

    Output format.
    Possible values are: utf8, svg, terminal.

See Options for other settings.

cb

Type: Function

Callback function called on finish.

Example
QRCode.toString('http://www.google.com', function (err, string) {
  if (err) throw err
  console.log(string)
})

toFile(path, text, [options], [cb(error)])

Saves QR Code to image file.
If options.type is not specified, the format will be guessed from file extension.
Recognized extensions are png, svg, txt.

path

Type: String

Path where to save the file.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options
  • type

    Type: String
    Default: png

    Output format.
    Possible values are: png, svg, utf8.

  • rendererOpts.deflateLevel (png only)

    Type: Number
    Default: 9

    Compression level for deflate.

  • rendererOpts.deflateStrategy (png only)

    Type: Number
    Default: 3

    Compression strategy for deflate.

See Options for other settings.

cb

Type: Function

Callback function called on finish.

Example
QRCode.toFile('path/to/filename.png', 'Some text', {
  color: {
    dark: '#00F',  // Blue dots
    light: '#0000' // Transparent background
  }
}, function (err) {
  if (err) throw err
  console.log('done')
})

toFileStream(stream, text, [options])

Writes QR Code image to stream. Only works with png format for now.

stream

Type: stream.Writable

Node stream.

text

Type: String|Array

Text to encode or a list of objects describing segments.

options

See Options.


Options

QR Code options

version

Type: Number

QR Code version. If not specified the more suitable value will be calculated.

errorCorrectionLevel

Type: String
Default: M

Error correction level.
Possible values are low, medium, quartile, high or L, M, Q, H.

maskPattern

Type: Number

Mask pattern used to mask the symbol.
Possible values are 0, 1, 2, 3, 4, 5, 6, 7.
If not specified the more suitable value will be calculated.

toSJISFunc

Type: Function

Helper function used internally to convert a kanji to its Shift JIS value.
Provide this function if you need support for Kanji mode.

Renderers options

margin

Type: Number
Default: 4

Define how much wide the quiet zone should be.

scale

Type: Number
Default: 4

Scale factor. A value of 1 means 1px per modules (black dots).

small

Type: Boolean
Default: false

Relevant only for terminal renderer. Outputs smaller QR code.

width

Type: Number

Forces a specific width for the output image.
If width is too small to contain the qr symbol, this option will be ignored.
Takes precedence over scale.

color.dark

Type: String
Default: #000000ff

Color of dark module. Value must be in hex format (RGBA).
Note: dark color should always be darker than color.light.

color.light

Type: String
Default: #ffffffff

Color of light module. Value must be in hex format (RGBA).


GS1 QR Codes

There was a real good discussion here about them. but in short any qrcode generator will make gs1 compatible 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

Credits

This lib is based on "QRCode for JavaScript" which Kazuhiko Arase thankfully MIT licensed.

License

MIT

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