• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

Lightweight library for stylish QR codes

QR Code Encoder

A lightweight library generating stylish QR codes that also support gradient fills and rounded corners in only 12.2kB minified (4.75kB gzipped). Try out the demo!

Origin

This library is a trimmed down version of Lars Jung's jQuery.qrcode library. Our library is however not based on jQuery anymore and doesnt make use of it. Lars Jung's library itself is based on this QR code Generator.

All parts are licensed under the MIT License.

Installation

To install via npm:

npm install --save qr-creator

To install via yarn:

yarn add qr-creator

Or use a cdn like jsdelivr or unpkg (see usage).

Usage

The library is available as a module and non-module version. To import it as a module:

  // from installed package for bundling with a module bundler like webpack:
  import QrCreator from 'qr-creator';
  // from cdn:
  import QrCreator from 'https://cdn.jsdelivr.net/npm/qr-creator/dist/qr-creator.es6.min.js';

To use the non-module version:

  <!-- from your project's code base -->
  <script src="path/to/qr-creator.min.js"></script>
  <!-- from cdn -->
  <script src="https://cdn.jsdelivr.net/npm/qr-creator/dist/qr-creator.min.js"></script>

Call the QrCreator API with a configuration object and a DOM element or canvas to render the QR code into:

  QrCreator.render({
    text: 'some text',
    radius: 0.5, // 0.0 to 0.5
    ecLevel: 'H', // L, M, Q, H
    fill: '#536DFE', // foreground color
    background: null, // color or null for transparent
    size: 128 // in pixels
  }, document.querySelector('#qr-code'));
Attribute Options Default Description
text String "" Any kind of text, also links, email addresses, any thing. The library will figure out the size of the QR code to fit all the text inside.
radius 0 .. 0.5 0.5 Defines how round the blocks should be. Numbers from 0 (squares) to 0.5 (maximum round) are supported.
ecLevel L, M, Q, H L Means "Error correction levels". The four values L, M, Q, and H will use %7, 15%, 25%, and 30% of the QR code for error correction respectively. So on one hand the code will get bigger but chances are also higher that it will be read without errors later on.
fill color or gradient #000000 What color you want your QR code to be. Use the demo to try different colors.
background color code null The background color or null for transparent background.
size int 200 The total size of the final QR code in pixels - it will be a square.

If you want to fill the QR code with a gradient, use the following format:

{
    type: 'radial-gradient', // or 'linear-gradient'
    position: [ ... ],
    colorStops: [
        [ offset0, color0 ],
        [ offset1, color1 ],
        ...
    ]
}

Where the position is specified as in createLinearGradient / createRadialGradient. However, each value is relative to the QR code size, i.e. will be multiplied by that size to yield the absolute position.

Trimmed down to be low weight

The goal of the library is to generate QR codes only. For that reason we have removed all additional code such as GIF image generation, background image support, rendering a label on top, removed some dead code, and freed it from depending on jQuery. Also, the resulting library does not use any global variables, is all strict mode, and relies on modern browser standards instead.

The result Original New
Lines of code 2332 1556 (-33%)
Size 64kB 50kB (-22%)
Minified 20.6kB 11.95kB (-40%)
Gzipped 7.3kB 4.77kB (-35%)

Building

To install the dependencies run:

npm install

and then to build the project:

npm run build

More Repositories

1

qr-scanner

Lightweight Javascript QR Code Scanner
TypeScript
2,420
star
2

core-js

Official JavaScript implementation of the Nimiq protocol
JavaScript
989
star
3

core-rs-albatross

Rust implementation of the Albatross protocol
Rust
159
star
4

core-rs

Official Rust implementation of the Nimiq protocol
Rust
74
star
5

jungle-db

A simple database abstraction layer for NodeJS (LMDB and LevelDB) and Browsers (IndexedDB) supporting advanced features such as transactions with read-isolation and secondary indices.
JavaScript
50
star
6

wallet

Browser Wallet for the Nimiq cryptocurrency
Vue
46
star
7

web-share-shim

A polyfill for the WebShare API
HTML
43
star
8

mining-pool

Nimiq Mining-Pool Server
JavaScript
39
star
9

identicons

Nimiq Identicons
JavaScript
32
star
10

nimiq-demo

Getting started with the Nimiq API
HTML
31
star
11

hub

The Nimiq Hub provides a unified interface for all Nimiq accounts, addresses, and contracts.
Vue
30
star
12

robohash

SVG Identicons based on Robohash
HTML
26
star
13

nimiq-exchange-token

Ethereum smart contract for the Nimiq Token Sale
JavaScript
25
star
14

woocommerce-gateway-nimiq

A plugin for WooCommerce to handle payments with Nimiq (NIM), Bitcoin (BTC) and Ethereum (ETH).
PHP
20
star
15

vue-components

Vue component library for Nimiq ecosystem apps.
Vue
17
star
16

electrum-client

API to interact with ElectrumX servers from browsers
TypeScript
13
star
17

keyguard

JavaScript
12
star
18

community

Community Site to gather contribution and nimiq-related content
SCSS
12
star
19

php-xpub

A simple class to derive BTC and ETH extended public keys and addresses without GMP.
PHP
10
star
20

web-miner

Nimiq web miner user interface
HTML
9
star
21

app-starter-kit

Starter kit for creating a Nimiq powered app.
Vue
9
star
22

jsonrpc

Rust implementation of a JSON-RPC client and server.
Rust
9
star
23

safe

JavaScript
8
star
24

nimiq-style

The Nimiq style framework.
HTML
8
star
25

nano-api

High-level API to the Nimiq nano client
TypeScript
8
star
26

mnemonic-phrase

Mnemonic phrases from HEX strings and vice-versa
JavaScript
8
star
27

elements

Nimiq User Interface Elements
JavaScript
7
star
28

crypto-map

The Crypto Map by Nimiq. Explore the world and find places to spend your crypto.
TypeScript
6
star
29

ledger-api

Api for communication with the Ledger Hardware Wallet Nimiq App.
TypeScript
6
star
30

nimiq.github.io

Nimiq Frontend Developer Reference
JavaScript
6
star
31

nimiq-utils

Simple helper libraries for Nimiq frontends
TypeScript
6
star
32

ceremony-attestations

5
star
33

albatross-simulator

A simulator for the Albatross protocol
Rust
4
star
34

network

TypeScript
4
star
35

x-element

Lightweight frontend framework
JavaScript
3
star
36

cards

Give NIM to others on a beautifully printed gift card.
Vue
3
star
37

php-utils

PHP Utilities for Nimiq
PHP
3
star
38

oasis-watch

A simple front-end to display OASIS HTLCs
Svelte
2
star
39

rfcs

RFCs for substantial changes & feature additions to Nimiq apps
2
star
40

merkle-mountain-range

A Rust implementation of Merkle Mountain Ranges.
Rust
2
star
41

cashlink-generator

Bulk Cashlink Creation and Management Tool
JavaScript
2
star
42

webpack-i18n-tools

JavaScript
2
star
43

core-types

Typescript typings for Nimiq core
2
star
44

vue3-components

Vue 3 component library for Nimiq ecosystem apps.
Vue
2
star
45

libswap-js

A Typescript handler class to handle and process atomic swaps with (not only) Fastspot.
TypeScript
2
star
46

ten31-pass-api

TypeScript
2
star
47

backup-file

Nimiq Wallet File Format designed for usability
JavaScript
2
star
48

oasis-api-js

Typed Javascript library to access OASIS APIs from the browser.
TypeScript
2
star
49

vote

The app running at nimiq.com/vote that is used for community-wide decisions.
TypeScript
2
star
50

albatross-monkey-chaos

TypeScript
1
star
51

doc-theme

Theme for Nimiq developer documentations
HTML
1
star
52

fastspot-api

Typescript library to interact with the Fastspot API
TypeScript
1
star
53

nimiqode

Encoder and decoder for hexagon-shaped QR-like code
JavaScript
1
star
54

albatross-doc

https://nimiq.github.io/albatross-doc/
SCSS
1
star
55

validators-api

TypeScript
1
star
56

developer-center

The Official documentation for the Nimiq ecosystem.
Vue
1
star
57

validator-registration-tool

JavaScript
1
star
58

browser-warning

Browser warnings for different cases of unsupported browsers, private modes, deactivated Javascript
JavaScript
1
star