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
- Kristian: Thanks, worked with a few modifications some paranthesis missing etc and did a response.write instead. Also nice with code that still works after 8 years ;) (commented on 9/18/2020 1:54:43 AM)
- Dina: still workin 15 jul 22 I love classic asp (commented on 7/15/2022 10:29:11 PM)
- zzxc: (commented on 12/9/2022 6:47:03 AM)
- Jesus Medina: Buenos Dias He intentado usar este codigo para generar QR desde asp y no me funciona ,la pagina queda en blanco , soy novato en esto, algo se me puede estar pasando , podrian orientarme , gracias (commented on 12/19/2022 4:27:28 PM)
- Jesus Medina: Buenos Dias He intentado usar este codigo para generar QR desde asp y no me funciona ,la pagina queda en blanco , soy novato en esto, algo se me puede estar pasando , podrian orientarme , gracias (commented on 12/19/2022 4:27:28 PM)
- Dev: function qrCode(strText, intSize) Dim strProtocol, strHTTPS, strDomain, strURL, strQueryString 'add Dim line if Option Explicit strHTTPS = lcase(request.ServerVariables("HTTPS")) 'ending paranthesis missing: added 'use like below <img src="<%=qrCode("string xyz", 150)%>" > (commented on 2/22/2023 7:51:38 PM)
Comment on this article