• Stars
    star
    1,454
  • Rank 32,350 (Top 0.7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure JavaScript library for QR code generation using canvas
 .d88888b.  8888888b.  d8b
d88P" "Y88b 888   Y88b Y8P
888     888 888    888
888     888 888   d88P 888  .d88b.  888  888 .d8888b
888     888 8888888P"  888 d88""88b 888  888 88K
888 Y8b 888 888 T88b   888 888  888 888  888 "Y8888b.
Y88b.Y8b88P 888  T88b  888 Y88..88P Y88b 888      X88
 "Y888888"  888   T88b 888  "Y88P"   "Y88888  88888P'
       Y8b

QRious is a pure JavaScript library for generating QR codes using HTML5 canvas.

Chat Demo Dev Dependency Status License Release

Install

Install using the package manager for your desired environment(s):

$ npm install --save qrious
# OR:
$ bower install --save qrious

If you want to simply download the file to be used in the browser you can find them below:

Check out node-qrious if you want to install it for use within Node.js.

Examples

<!DOCTYPE html>
<html>
  <body>
    <canvas id="qr"></canvas>

    <script src="/path/to/qrious.js"></script>
    <script>
      (function() {
        var qr = new QRious({
          element: document.getElementById('qr'),
          value: 'https://github.com/neocotic/qrious'
        });
      })();
    </script>
  </body>
</html>

Open up demo.html in your browser to play around a bit.

API

Simply create an instance of QRious and you've done most of the work. You can control many aspects of the QR code using the following fields on your instance:

Field Type Description Default Read Only
background String Background color of the QR code "white" No
backgroundAlpha Number Background alpha of the QR code 1.0 No
element Element Element to render the QR code <canvas> Yes
foreground String Foreground color of the QR code "black" No
foregroundAlpha Number Foreground alpha of the QR code 1.0 No
level String Error correction level of the QR code (L, M, Q, H) "L" No
mime String MIME type used to render the image for the QR code "image/png" No
padding Number Padding for the QR code (pixels) null (auto) No
size Number Size of the QR code (pixels) 100 No
value String Value encoded within the QR code "" No
var qr = new QRious();
qr.background = 'green';
qr.backgroundAlpha = 0.8;
qr.foreground = 'blue';
qr.foregroundAlpha = 0.8;
qr.level = 'H';
qr.padding = 25;
qr.size = 500;
qr.value = 'https://github.com/neocotic/qrious';

The QR code will automatically update when you change one of these fields, so be wary when you plan on changing lots of fields at the same time. You probably want to make a single call to set(options) instead as it will only update the QR code once:

var qr = new QRious();
qr.set({
  background: 'green',
  backgroundAlpha: 0.8,
  foreground: 'blue',
  foregroundAlpha: 0.8,
  level: 'H',
  padding: 25,
  size: 500,
  value: 'https://github.com/neocotic/qrious'
});

These can also be passed as options to the constructor itself:

var qr = new QRious({
  background: 'green',
  backgroundAlpha: 0.8,
  foreground: 'blue',
  foregroundAlpha: 0.8,
  level: 'H',
  padding: 25,
  size: 500,
  value: 'https://github.com/neocotic/qrious'
});

You can also pass in an element option to the constructor which can be used to generate the QR code using an existing DOM element, which is the only time that you can specify read only options. element must either be a <canvas> element or an <img> element which can then be accessed via the canvas or image fields on the instance respectively. An element will be created for whichever one isn't provided or for both if no element is specified, which means that they can be appended to the document at a later time.

var qr = new QRious({
  element: document.querySelector('canvas'),
  value: 'https://github.com/neocotic/qrious'
});

qr.canvas.parentNode.appendChild(qr.image);

A reference to the QRious instance is also stored on both of the elements for convenience.

var canvas = document.querySelector('canvas');
var qr = new QRious({
  element: canvas,
  value: 'https://github.com/neocotic/qrious'
});

qr === canvas.qrious;
//=> true

toDataURL([mime])

Generates a base64 encoded data URI for the QR code. If you don't specify a MIME type, it will default to the one passed to the constructor as an option or the default value for the mime option.

var qr = new QRious({
  value: 'https://github.com/neocotic/qrious'
});

qr.toDataURL();
//=> "data:image/png;base64,iVBOR...AIpqDnseH86KAAAAAElFTkSuQmCC"
qr.toDataURL('image/jpeg');
//=> "data:image/jpeg;base64,/9j/...xqAqIqgKFAAAAAq3RRQAUUUUAf/Z"

Migrating from older versions

If you've been using an older major version and would like details on what's changed and information on how to migrate to the latest major release below:

https://github.com/neocotic/qrious/wiki/Migrating-from-older-versions

Bugs

If you have any problems with QRious or would like to see changes currently in development you can do so here. Core features and issues are maintained separately here.

Contributors

If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!

A list of QRious contributors can be found in AUTHORS.md.

License

Copyright © 2017 Alasdair Mercer
Copyright © 2010 Tom Zerucha

See LICENSE.md for more information on our GPLv3 license.

More Repositories

1

convert-svg

Node.js packages for converting SVG into other formats using headless Chromium
JavaScript
174
star
2

europa

Library for converting HTML into valid Markdown
TypeScript
154
star
3

injector-chrome

Chrome extension that allows you to create custom code snippets to be injected into any website
CoffeeScript
34
star
4

yourls-api

JavaScript bindings for the YOURLS API
JavaScript
22
star
5

qrious-core

QRious core engine for QR code generation
JavaScript
13
star
6

node-qrious

Node.js module for QR code generation via QRious
JavaScript
9
star
7

node-europa

Node.js module for converting HTML into valid Markdown via Europa
8
star
8

mor.js

Pure JavaScript library for encoding/decoding Morse code messages
JavaScript
7
star
9

escape-unicode

Node.js library to escape Unicode
JavaScript
6
star
10

date-ext

Library for extending JavaScript dates
JavaScript
5
star
11

int17

Internationalization JavaScript library
JavaScript
4
star
12

jquery-console

jQuery console simulation plugin
JavaScript
4
star
13

brick-pop-solver

Solver for the Brick Pop facebook messenger game
Java
4
star
14

jsonx

Pure JavaScript library to support XML to JSON transformations and vice versa
JavaScript
4
star
15

css-utils

Utility for providing common CSS3 classes
CSS
3
star
16

jsonp.js

Simple JSONP JavaScript library
JavaScript
3
star
17

europa-core

3
star
18

Backbone.Do

Backbone plugin to make model actions doable
JavaScript
3
star
19

pathlength

Checks the lengths of file paths
JavaScript
3
star
20

europa-branding

Branding assets and guidelines for Europa
2
star
21

throne

Name availability checker
JavaScript
2
star
22

moan

Simple task-based JavaScript build system
JavaScript
2
star
23

europa-test

2
star
24

node-native2ascii

Node.js implementation of Java's Native-to-ASCII Converter
JavaScript
2
star
25

jquery-jsonx

jQuery plugin to support XML to JSON transformations and vice versa
JavaScript
2
star
26

unescape-unicode

Node.js library to convert Unicode escapes
JavaScript
2
star
27

phony.js

Pure JavaScript library for translating to/from the phonetic alphabet
JavaScript
2
star
28

grunt-html-md

Convert HTML files into Markdown
JavaScript
1
star
29

mercer.scot

HTML
1
star
30

featuring

Simple lightweight immutable feature toggle implementation
JavaScript
1
star
31

brander

A tool for generating branding assets and documentation
JavaScript
1
star
32

branding

Branding assets and guidelines for me, neocotic
1
star
33

squire-behaviours

Allows you to improve the behaviour of your squire
CoffeeScript
1
star
34

eslint-config-skelp

Standard ESLint configurations for Skelp packages
JavaScript
1
star
35

skelp.io

HTML
1
star
36

confij

Simple configuration from any source and format
CoffeeScript
1
star
37

wal

Web application launcher
Java
1
star
38

mail-manager

Engine for mail-manager.appspot.com
Java
1
star
39

pollock

A simple lightweight JavaScript library for adding abstract methods to types
JavaScript
1
star
40

broonline

Fun project for tracking the use of broon sauce at chippies
JavaScript
1
star
41

UndoWikipediaBlackout

[NO LONGER MAINTAINED] Google Chrome extension that removes the blackout on Wikipedia
CoffeeScript
1
star
42

properties-store

Store for .properties files in Node.js
JavaScript
1
star
43

squire

Your own personal squire to boss around
CoffeeScript
1
star
44

iOrder

[NO LONGER MAINTAINED] Google Chrome extension that keeps users updated with their iDevice order progress
HTML
1
star
45

moan-sample

A sample project for using the the moan build tool
JavaScript
1
star