QR Code generator for browser and node.js with tree shaking and logo support (based on alexeyten/qr-image).
- generate image in
png
,svg
andpdf
formats - numeric and alphanumeric modes
- support UTF-8
- supports color customization
- supports logos
- tree shaking support
- browser / node.js
npm install @shortcm/qr-image
# or
yarn add @shortcm/qr-image
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)'})
getPNG(text, [options])
: Readable stream with image data.getSVG(text, [options])
: Readable stream with image data.getPDF(text, [options])
: Readable stream with image data.
text
: text to encodeoptions
: additional image options object
Name | Description | Type | Possible Values | Default |
---|---|---|---|---|
ec_level |
error correction level | string | L , M , Q , H |
M |
type |
image type | string | png , svg , pdf |
png |
size |
png and svg only size of one module in pixels |
number | 0 - n |
5 (png)0 (others) |
margin |
white space around QR image in modules | number | 0 - n |
4 (png)1 (others) |
parse_url |
EXPERIMENTAL try to optimize QR-code for URLs |
boolean | true , false |
false |
logo |
buffer with png image | Buffer | - | undefined |
logoWidth |
height of logo in percent | number | 0 - 100 |
20 |
logoHeight |
width of logo in percent | number | 0 - 100 |
20 |
color |
module color in rgba or hex format | number | #000000 - #000000 |
#000000 (black with 100% opacity) |
bgColor |
background color in rgba or hex format | number | #000000 - #FFFFFF |
#FFFFFF (white with 100% opacity) |
getPNG x 98.36 ops/sec ±0.61% (69 runs sampled)
getPDF x 118 ops/sec ±16.68% (87 runs sampled)
getSVG x 2,902 ops/sec ±0.18% (89 runs sampled)
getPNG with logo x 52.49 ops/sec ±0.45% (82 runs sampled)
getPDF with logo x 39.29 ops/sec ±8.17% (68 runs sampled)
getSVG with logo x 2,817 ops/sec ±0.17% (89 runs sampled)
- Use lighter versions of PDF library
- Round corners
- Transparency
- Background