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 size × (matrix width + 2 × margin).

QRCodePNGRendererOptions accepts the shared visual options plus:

Option Type Default Effect
compressionLevel integer 09 9 Sets the PNG DEFLATE compression level
image.source Buffer required with image Supplies already-read PNG bytes for a center image
image.size number 0.4 Image box as a fraction of matrix width
image.padding number 1 Clear padding measured in modules
image.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.

  • compressionLevel must be a safe integer from 0 through 9.
  • image.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.