QR code generator: the JavaScript library

Styled QR codes: dot and corner shapes, colors and gradients, a logo in the middle, frames with a caption. Export to PNG, JPEG, WebP and SVG. Built on qr-code-styling.

  • @openlibsdev/qr-code-generator
  • v1.0.0
  • ES module
  • MIT

Installation

With a bundler or Node-style imports:

npm install @openlibsdev/qr-code-generator
import QrCodeGenerator from "@openlibsdev/qr-code-generator";

Or straight in a page, without a build step (jsDelivr resolves the dependencies):

<script type="module">
import QrCodeGenerator from "https://cdn.jsdelivr.net/npm/@openlibsdev/qr-code-generator@1.0.0/+esm";
</script>

Usage

import QrCodeGenerator from "@openlibsdev/qr-code-generator";

const state = QrCodeGenerator.normalize({ data: "https://openlibs.dev", dotsColor: "#0d6efd" });
const qr = QrCodeGenerator.create(state);        // a QRCodeStyling instance
qr.append(document.body);
const blob = await QrCodeGenerator.toBlob(state, "svg");

API

QrCodeGenerator.normalize(input)

Makes full settings from a partial object.

QrCodeGenerator.create(state, override)

Creates a QR code (a QRCodeStyling instance) from the settings; show it with append(element).

QrCodeGenerator.toBlob(state, extension)

QR code as a file: png, jpeg, webp or svg.

QrCodeGenerator.toOptions(state)

Settings → the options object of qr-code-styling.

QrCodeGenerator.fromOptions(o)

Options object of qr-code-styling → settings.

QrCodeGenerator.applyPreset(state, name)

Applies a ready style.

QrCodeGenerator.PRESETS

Ready styles.

QrCodeGenerator.DEFAULTS

Default settings.

QrCodeGenerator.LISTS

Allowed values: dot and corner shapes, error correction levels and others.

QrCodeGenerator.APP

Name, version and release date of the library: {name, version, created}.

QrCodeGenerator.QRCodeStyling()

The qr-code-styling class itself, for features not covered by this library.

QrCodeGenerator.findNamedColor(text, lang)

Finds a named color by its name in the given language ("dark blue" → #00008b).

QrCodeGenerator.frameExtension(state)

The frame with a caption around an SVG code, as a qr-code-styling extension (pass it to applyExtension).

QrCodeGenerator.listNamedColors(lang)

Lists the named colors with their names in the given language.

QrCodeGenerator.mimeFor(ext)

MIME type of a file extension (png, jpeg, webp, svg).

QrCodeGenerator.namedColorTexts(lang)

Labels of the color field in the given language (the texts of the color picker), English for a missing language.

Dependencies

What the library loads, with the licenses (all are listed on the Licenses page).

NameVersionLicenseFiles
@openlibsdev/font-forge1.0.0MITGitHub
@openlibsdev/image-forge1.0.0MITGitHub
@imagemagick/magick-wasm0.0.35Apache-2.0 License · Source code
@imagemagick/magick-wasm0.0.35Apache-2.0 License · Source code
@simonwep/pickr1.10.2MIT License · Source code
@simonwep/pickr1.10.2MIT License · Source code
dejavu-fonts-ttf2.37.3Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain License · Source code
imagetracerjs1.2.6Unlicense License · Source code
jspdf2.5.2MIT License · Source code
qr-code-styling1.9.2MIT License · Source code