Skip to content

@qrcodesdk/node

Node.js renderers for QRCodeSDK. Use this package with @qrcodesdk/core when you need a PNG, WebP, GIF, or JPEG Buffer for files, HTTP responses, downloads, email attachments, or other server-side integrations.

Terminal window
npm install @qrcodesdk/core @qrcodesdk/node
import {qrcode} from '@qrcodesdk/core';
import {QRCodePNGRenderer} from '@qrcodesdk/node';
const png = qrcode('https://qrcodesdk.dev').render(QRCodePNGRenderer());

QRCodePNGRenderer() returns a Node.js Buffer containing a square PNG image. RGB and RGBA style colors are preserved, including transparent backgrounds.

Format Renderer Content-Type Choose it when
PNG QRCodePNGRenderer image/png The destination needs the most widely supported raster format
WebP QRCodeWebPRenderer image/webp The destination accepts WebP and file size matters
GIF QRCodeGIFRenderer image/gif The destination only accepts GIF
JPEG QRCodeJPEGRenderer image/jpeg The destination only accepts JPEG, or the center image is a photo

All four renderers draw the same pixels from the same style and centerImage options and return a Buffer. WebP output is lossless and usually much smaller than PNG; a default QR code for https://qrcodesdk.dev is about 310 bytes as WebP and 1.1 KB as PNG. GIF output is a single frame with at most 256 colors and binary transparency: pixels below transparency.threshold alpha become transparent and all others opaque. JPEG output is lossy and has no transparency: transparent pixels are blended onto transparency.matte, white by default. It is about 9.7 KB for the same QR code, or 870 bytes with a module size of 8, so use it only when the destination requires JPEG or a photographic center image benefits from it.

import {qrcode} from '@qrcodesdk/core';
import {QRCodeGIFRenderer, QRCodeJPEGRenderer, QRCodeWebPRenderer} from '@qrcodesdk/node';
const builder = qrcode('https://qrcodesdk.dev');
const webp = builder.render(QRCodeWebPRenderer());
const gif = builder.render(QRCodeGIFRenderer());
const jpeg = builder.render(QRCodeJPEGRenderer({quality: 90}));

See the PNG, WebP, GIF, and JPEG Buffer renderers for their options and exact constraints. Center images created with rasterCenterImage() from PNG bytes work with all four renderers. Follow Download or save to write a Buffer to disk or Serve a QR code to return it with its media type.

@qrcodesdk/node directly supports Node.js 22.0.0 or newer. Bun and Deno are supported through their Node.js compatibility layers.

The public TypeScript API uses Node’s global Buffer type. TypeScript consumers must include @types/node in their development dependencies and make Node types available in their TypeScript options.

import {
QRCodeGIFRenderer,
type QRCodeGIFRendererOptions,
QRCodeJPEGRenderer,
type QRCodeJPEGRendererOptions,
QRCodePNGRenderer,
type QRCodePNGRendererOptions,
type QRCodeRasterCenterImage,
type QRCodeRasterRendererOptions,
QRCodeWebPRenderer,
type QRCodeWebPRendererOptions,
rasterCenterImage,
} from '@qrcodesdk/node';

@qrcodesdk/node

Version
v0.0.5
Downloads
254/mo
Install size
87.3 kB
Bundled size
12.9 kB
Works with
Works with Node.jsWorks with BunWorks with Deno

Support QRCodeSDK

If you find QRCodeSDK useful, please consider sponsoring the project!