# QR code generator — library for developers

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.

## Installation

```sh
npm install @openlibsdev/qr-code-generator
```

```js
import QrCodeGenerator from "https://cdn.jsdelivr.net/npm/@openlibsdev/qr-code-generator@1.0.0/+esm";
```

## Usage

```js
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

- @imagemagick/magick-wasm 0.0.35 (Apache-2.0)
- @imagemagick/magick-wasm 0.0.35 (Apache-2.0)
- @simonwep/pickr 1.10.2 (MIT)
- @simonwep/pickr 1.10.2 (MIT)
- dejavu-fonts-ttf 2.37.3 (Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain)
- imagetracerjs 1.2.6 (Unlicense)
- jspdf 2.5.2 (MIT)
- qr-code-styling 1.9.2 (MIT)

- GitHub: https://github.com/OpenLibsDev/qr-code-generator
- npm: https://www.npmjs.com/package/@openlibsdev/qr-code-generator
- Open the app: https://openlibs.dev/en/app/qr-code-generator/
