Tech Talk

Permanent link to Automatically Create QR Codes in ASP Automatically Create QR Codes in ASP

Tuesday, August 28, 2012

Here's a cool application for a QR Code: print it out and include it in a scrapbook or photo album for quick access to media (like video) that can't (yet) be included in a book! Cool, right? So, I needed to find a way to automatically generate the codes in Classic ASP. I found a couple libraries out there, but by far the quickest way is to use Google's Infographics tool.

This comes in really handy especially on my photo search results page, which has long URL strings.

I created a function to create a QR code from any page on this site. I added some logic to build the page string, but still allow the function to be called with any string, but checking for the word "this"

	function qrCode(strText,intSize)
	    if strText = "this" then
	        strProtocol = "http"
	        strHTTPS = lcase(request.ServerVariables("HTTPS"))
	        if strHTTPS <> "off" then strProtocol = "https"
	        strDomain = Request.ServerVariables("SERVER_NAME")
	        strURL = Request.ServerVariables("SCRIPT_NAME")
	        strQueryString = Request.ServerVariables("QUERY_STRING")
	        strText = strProtocol & "://" & strDomain & strURL & "?" & strQueryString
	    end if

	    qrCode = "https://chart.googleapis.com/chart?cht=qr&chs=" & intSize & "x" & intSize & "&chld=L|1&chl=" & server.URLEncode(strText)

	end function

So to use, I can simply call:

        qrCode("this",150)

Update 2024

Google's Chart APIs has been turned off after years of deprecation, breaking this functionality. Ah, the joy of depending on Google services!

There's another provider who has built a QR Code generator, and clearly has built their tool to replace Google's, because they support the identical set of URL parameters:

https://image-charts.com/chart

"Image-Charts" as a company is quite opaque, but the Terms link it to a Francois-Guillaume Ribreau. Only time will tell if his services will last another decade+ so we can still enjoy simple QR codes in Classic ASP!

6 Comments

LaRocque Family