The bx-image module can now generate and read QR codes. Two new functions, a string member function, and two new bx:image actions. No extra dependencies for you to manage.
Here is what it looks like.
qr = ImageQRCodeGenerate( "https://boxlang.io", 250 )
ImageWrite( qr, "/path/to/qr.png" )

The result is a regular BoxLang image. Resize it, add a border, write it as Base64, or drop it in a template. Every image function you already know works on it.
Make it yours
Pick the size, format, colors, and how much damage the code can survive and still scan.
qr = ImageQRCodeGenerate(
text = "https://boxlang.io",
size = 250,
errorCorrection = "H",
foreground = "#1a237e",
background = "#ffeb3b"
)

You can also drop a logo in the center. A logo hides part of the code, so BoxLang raises the error correction to H for you and then scans the result. If the logo makes the code unreadable, you get a clear error instead of a code that quietly fails in someone's hand.
qr = ImageQRCodeGenerate( text="https://example.com/with-logo", size=400, logo="/path/to/logo.png" )

A member function, too
qr = "https://boxlang.io".toQRCode( 250 )
Read them back
img = ImageRead( "/path/to/qr.png" )
text = ImageQRCodeRead( img )
// or as a member function
text = img.readQRCode()
If there is no QR code in the image, you get an empty string back. Light-on-dark codes are read too.
In templates
The bx:image component gets two new actions, matching how captcha works.
<bx:image action="qrcode" text="https://boxlang.io" size="250" name="qr" />
<bx:image action="qrread" source="/path/to/qr.png" name="decoded" />
With no name or destination, qrcode streams the image straight to the browser, just like captcha.
Get it
install bx-image
Already installed? Update the module to pick up the new functions.
Full reference for ImageQRCodeGenerate and ImageQRCodeRead is in the BoxLang docs. Found something odd or want another option? Open an issue.
Add Your Comment