PNG Buffer renderer
When to use
Section titled “When to use”Use QRCodePNGRenderer when Node.js-compatible code needs PNG bytes for a file, HTTP response,
attachment, object store, or another binary API.
Minimal example
Section titled “Minimal example”import {qrcode} from '@qrcodesdk/core';import {QRCodePNGRenderer} from '@qrcodesdk/node';
const png = qrcode('https://qrcodesdk.dev').render(QRCodePNGRenderer());Return value
Section titled “Return value”The renderer synchronously returns a Node.js Buffer containing a complete PNG file. Its pixel
width and height are size × (matrix width + 2 × margin).
Renderer-specific options
Section titled “Renderer-specific options”QRCodePNGRendererOptions accepts the
shared visual options plus:
| Option | Type | Default | Effect |
|---|---|---|---|
compressionLevel |
integer 0–9 |
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.
Renderer-specific constraints
Section titled “Renderer-specific constraints”compressionLevelmust be a safe integer from0through9.image.sourcemust be a Node.jsBuffercontaining 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.
Related guides
Section titled “Related guides”- Customize appearance for shared styling and scan safety.
- Add a center image for reading and sizing a PNG overlay.
- Download or save for writing the
Bufferto disk. - Serve a QR code for
image/pngHTTP responses.