Skip to main content

Rendering QR Codes With Zxing And ColdFusion

By Web Design13 min read

Last week, I looked at rendering 1-dimensional bar codes with Zxing and ColdFusion. The Zxing Java library creates a really flexible abstraction. Basically, it provides a bunch of “writers” that can encode different barcode formats into a “bit matrix” (a 2D representation of on/off pixels); and then, it provides a way to generically render that bit matrix into an image. As a follow-up post, I wanted to look at rendering QR Codes since this flavor of barcode has really become quite popular over the last few years (especially since the pandemic).

One of the really cool features of the QR code rendering is that it can absorb a certain degree of “error correction”. Which means, parts of the QR code can be obscured and the barcode scanner will still properly interpret the encoded data. The level of applied error correction determines how much of the QR code can be obscured without breaking the functionality. And, the greater the degree of error correction, the larger the QR code rendering has to be.

When you go to a restaurant and they provide a touch-free menu via a QR code; and, the restaurant has included its logo in the middle of the QR code; well, that’s not part of the QR code specification. They are just taking advantage of the error correction functionality. So as long as the branding / logo doesn’t obscure more than the error correction can account for, the QR code still works.

I had no idea this was how QR codes worked. So cool.

Just as with my previous Zxing and ColdFusion demo, I’m going to be using Lucee CFML’s ability to load Java classes from a set of JAR files:


	/**
	* I create a Java class from the given JAR files using an isolated classloader.
	*/
	private any function fromJars( required string classname ) {
		var jarPaths = [
			expandPath( "./vendor/com.google.zxing/3.5.3/core-3.5.3.jar" ),
			expandPath( "./vendor/com.google.zxing/3.5.3/javase-3.5.3.jar" )
		];
		return createObject( "java", classname, jarPaths );
	}

Ok, let’s start exploring.

Check out the license.


https://bennadel.com/4808


Source link

© WebSocial Toronto – Digital Expertise with a Human Touch