9.0.4 • Published 5 months ago

@shortcm/qr-image v9.0.4

Weekly downloads
26
License
MIT
Repository
github
Last release
5 months ago

@shortcm/qr-image

npm version

QR Code generator for browser and node.js with tree shaking and logo support (based on alexeyten/qr-image).

image

Overview

  • generate image in png, svg and pdf formats
  • numeric and alphanumeric modes
  • support UTF-8
  • supports color customization
  • supports logos
  • tree shaking support
  • browser / node.js

Releases

Installing

npm install @shortcm/qr-image
# or
yarn add @shortcm/qr-image

Usage

Example:

import { getSVG } from "@shortcm/qr-image/lib/svg";
import { getPNG } from "@shortcm/qr-image/lib/png"; // imports canvas implementation in browser and sharp module in node.js
import { getPDF } from "@shortcm/qr-image/lib/pdf"; // this import is large, consider async import
const svgString = await getSVG("I love QR", {
    logo: fs.openFileSync("my-logo.svg"),
    color: "#000000",
    bgColor: "#FFFFFF",
});
const pngBuffer = await getPNG("I love QR", {
    logo: fs.openFileSync("my-logo.svg"),
    color: "rgb(0, 0, 0)",
    bgColor: "rgb(255, 255, 255)",
});

More examples

Syntax

  • getPNG(text, [options]): Readable stream with image data.
  • getSVG(text, [options]): Readable stream with image data.
  • getPDF(text, [options]): Readable stream with image data.

Options

  • text: text to encode
  • options: additional image options object

Additional Options

NameDescriptionTypePossible ValuesDefault
ec_levelerror correction levelstringL, M, Q, HM
typeimage typestringpng, svg, pdfpng
sizepng and svg onlysize of one module in pixelsnumber0 - n5 (png)0 (others)
marginwhite space around QR image in modulesnumber0 - n4 (png)1 (others)
parse_urlEXPERIMENTALtry to optimize QR-code for URLsbooleantrue, falsefalse
logobuffer with png/jpeg imageArrayBuffer-undefined
logoWidthheight of logo in percentnumber0 - 10020
logoHeightwidth of logo in percentnumber0 - 10020
colormodule color in rgba or hex formatnumber#000000 - #000000#000000(black with 100% opacity)
bgColorbackground color in rgba or hex formatnumber#000000 - #FFFFFF#FFFFFF(white with 100% opacity)
borderRadiusborder-radius (in pixels)number0 - size / 20

Benchmarks

getPNG x 229 ops/sec ±0.45% (84 runs sampled)
getPDF x 186 ops/sec ±24.91% (86 runs sampled)
getSVG x 2,482 ops/sec ±0.18% (90 runs sampled)
getPNG with logo x 69.96 ops/sec ±0.72% (68 runs sampled)
getPDF with logo x 44.83 ops/sec ±9.52% (77 runs sampled)
getSVG with logo x 2,494 ops/sec ±0.19% (88 runs sampled)

TODO

  • Use lighter versions of PDF library
  • Background
9.0.4

5 months ago

9.0.3

5 months ago

8.1.0

8 months ago

8.0.1

8 months ago

8.0.0

8 months ago

8.1.1

8 months ago

9.0.2

8 months ago

9.0.1

8 months ago

9.0.0

8 months ago

7.0.0

1 year ago

7.0.2

1 year ago

7.0.1

1 year ago

5.1.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

6.1.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.2.0

2 years ago

6.0.0-0

2 years ago

4.6.1

2 years ago

4.6.0

3 years ago

4.5.1

3 years ago

4.4.4

3 years ago

4.4.3

3 years ago

4.4.1

3 years ago

4.4.0

3 years ago

4.4.2

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.12

3 years ago

4.1.10

4 years ago

4.1.8

4 years ago

4.1.9

4 years ago

4.1.7

4 years ago

4.1.6

4 years ago

4.1.3

4 years ago

4.1.5

4 years ago

4.1.2

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago