Skip to content

PNG Buffer renderer

Use QRCodePNGRenderer when Node.js-compatible code needs PNG bytes for a file, HTTP response, attachment, object store, or another binary API.

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

The renderer synchronously returns a Node.js Buffer containing a complete PNG file. Its pixel width and height are style.moduleSize × (matrix width + 2 × style.quietZone).

QRCodePNGRendererOptions accepts style, centerImage, and compression. It rejects every other key.

Option Type Default Effect
style QRCodeVisualStyle shared defaults Applies graphical dimensions, colors, and shapes
compression.level integer 0–9 9 Sets the PNG DEFLATE compression level
centerImage.source Buffer required with centerImage Supplies already-read PNG bytes for a center image
centerImage.size number 0.4 Image box as a fraction of matrix width
centerImage.padding number 1 Clear padding measured in modules
centerImage.clearBackground boolean true Clears modules behind the image and padding

Compression changes encoding effort and file size, not the rendered QR modules. A level of 0 disables DEFLATE compression; 9 requests the highest level.

  • compression.level must be a safe integer from 0 through 9.
  • centerImage.source must be a Node.js Buffer containing valid PNG bytes. Other formats, paths, and URLs are not decoded.
  • Center images preserve aspect ratio, are composited with alpha, and are contained within the configured square without cropping.
  • Options are validated and copied when QRCodePNGRenderer() is called. The source Buffer is kept by identity and decoded when rendering.