qrCodeGenerate

Generates a QR code encoding the given text and returns it as a Binary of encoded image bytes. The module grid is drawn at the largest whole-pixel scale that fits the requested size and then nearest-neighbour resized to hit size on the nose (scaling a QR with a smoothing filter blurs the module edges and can make it unreadable). size is the target edge length in pixels (the result is square, clamped to 16-4096); format is any format the image BIFs write (png, gif, jpg, bmp, webp, ...); errorCorrection is L, M, Q or H; quietZone is the light margin in modules (the QR spec requires 4).

qrCodeGenerate(text [, size [, format [, errorCorrection [, quietZone]]]]) → returns binary

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

text string
Required

The text to encode. Required and must be non-empty.

size numeric
Default: 125

Target edge length in pixels (the result is square). Clamped to 16-4096.

format string
Default: png

Image format of the encoded output: png, gif, jpg, bmp, webp, tiff or ico.
Values:
  • png
  • gif
  • jpg
  • bmp
  • webp
  • tiff
  • ico

errorCorrection string
Default: M

Error-correction level: L, M, Q or H — the proportion of the symbol that can be damaged and still decode.
Values:
  • L
  • M
  • Q
  • H

quietZone numeric
Default: 4

The mandatory light margin, in modules (the QR spec requires 4). Clamped to 0-32.

Examples
Sample code invoking the qrCodeGenerate function

Encode a URL and write the 250px PNG to disk.

qr = qrCodeGenerate( "https://example.com/verify", 250, "png" );
imageWrite( qr, expandPath( "/qr.png" ) );

A 125px GIF with H error correction, suitable for printing.

qr = qrCodeGenerate( "ME:12345678", 125, "gif", "H" );

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub