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 style.moduleSize × (matrix width + 2 × style.quietZone).
Renderer-specific options
Section titled “Renderer-specific options”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.
Renderer-specific constraints
Section titled “Renderer-specific constraints”compression.levelmust be a safe integer from0through9.centerImage.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.
- Options are validated and copied when
QRCodePNGRenderer()is called. The source Buffer is kept by identity and decoded when rendering.
Related guides
Section titled “Related guides”- Customize appearance for shared styling and scan reliability.
- Add a center image for reading and sizing a PNG center image.
- Download or save for writing the
Bufferto disk. - Serve a QR code for
image/pngHTTP responses.