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-generatorimport 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).
| Name | Version | License | Files |
|---|---|---|---|
| @openlibsdev/font-forge | 1.0.0 | MIT | GitHub |
| @openlibsdev/image-forge | 1.0.0 | MIT | GitHub |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | License · Source code |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | License · Source code |
| @simonwep/pickr | 1.10.2 | MIT | License · Source code |
| @simonwep/pickr | 1.10.2 | MIT | License · Source code |
| dejavu-fonts-ttf | 2.37.3 | Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain | License · Source code |
| imagetracerjs | 1.2.6 | Unlicense | License · Source code |
| jspdf | 2.5.2 | MIT | License · Source code |
| qr-code-styling | 1.9.2 | MIT | License · Source code |