This is a fork of qr-image that works on CloudFlare Workers. It replaces the CommonJS require
with ES6 import
and updates all dependencies to use the new node:<module>
import syntax. It also removes the zlib
dependency and replaces it with pako
to work around the lack of zlib
in CloudFlare Workers.
This is yet another the best Cloudflare QR Code generator.
No dependeciesOnlypako
for CloudFlare Workers, becausezlib
is not available;- generate image in
png
,svg
,eps
andpdf
formats; - numeric and alphanumeric modes;
- support UTF-8.
npm install git+git@github.com:SteffTek/cf-qr-image.git#main
Maybe I'll publish it to npm at some point, but for now you'll have to use the git URL.
Example:
import qr from 'qr-image';
const qr_svg = qr.imageSync('I love QR!', { type: 'svg' });
qr.image(text, [ec_level | options])
— Readable stream with image data;qr.imageSync(text, [ec_level | options])
— string with image data. (Buffer forpng
);qr.svgObject(text, [ec_level | options])
— object with SVG path and size;qr.matrix(text, [ec_level])
— 2D array of booleans. Y is indexed first (e.g.[y][x]
NOT[x][y]
),[0][0]
is the top left, andtrue
means black.
text
— text to encode;ec_level
— error correction level. One ofL
,M
,Q
,H
. DefaultM
.options
— image options object:ec_level
— defaultM
.type
— image type. Possible valuespng
(default),svg
,pdf
andeps
.size
(png and svg only) — size of one module in pixels. Default5
for png andundefined
for svg.margin
— white space around QR image in modules. Default4
forpng
and1
for others.customize
(only png) — function to customize qr bitmap before encoding to PNG.parse_url
(experimental, defaultfalse
) — try to optimize QR-code for URLs.
UseUsezlib.deflateSync
instead ofpako
.pako
instead ofzlib
to work around the lack ofzlib
in CloudFlare Workers.
- Tests;
- mixing modes;
- Kanji (???).