Generate QR Codes with ColdFusion Component

This morning I released an updated version of my ColdFusion CFC Wrapper, which is now at version 2.0.

The core reason for the update was to provide the new methods now included within the official API.

What’s changed?

There are four official new methods that have been added into the ColdFusion wrapper for the API, which are:

These methods are a great way to provide a little analytical data for any generated URLs. Superb stuff and incredibly easy to obtain, especially though the CFC.

QR Codes

A significant addition to the service is the ability to generate Quick Response (QR) codes, or data matrix barcodes - those awesome little 2D barcodes that can be read by most smartphones, scanners etc.. a perfect way of storing and publishing text, information, or most commonly, a URL.

Iron Man QR Code It's not new technology, it's not really a new idea, but with the constant release of smartphones and devices capable of reading them (and so much more) it's becoming more common-place within today's society.

Naturally, as a format widely accessible to not only providers but also consumers, it's become a '2.0' option of delivery for marketing campaigns and advertising - an ideal, enigmatic way to promote your services or products.

Lost QR Code

As reported in Mashable, Google recently released their URL shortening service, which by all accounts included QR Code generation from the start. As such, it wasn't a surprise to see step up and include this support in their services to ensure that their users weren't missing out on the same capabilities.

Grabbing a QR Code

Although not an official method included within the API, ColdFusion makes it incredibly easy to obtain and retrieve this information, it has been included within the CFC.

Here's how easy it is to generate the QR Code using the CFC:

    Instantiate the object.
<cfset objBitly = createObject('component',
            username    =    '< your account username >',
            apikey        =    '< your api key >',
            parse        =    true
        ) />

    The generateQRCode() method returns binary data
    (the byte array) of the generated image.
<cfset qrResponse = objBitly.generateQRCode(
                        shortURL    = ''
                    ) />

    Dump out the binary response from the
    initial call (just to see what was returned).
<cfdump var="#qrResponse#"
        label="QRCode binary response" />

    Write the binary data as an image and display
    directly into the browser. Thanks, ColdFusion.
<cfimage action="writeToBrowser"
         source="#qrResponse#" />

The returned response from the cfdump of the binary data is shown below:

QR Code Binary Dump

And the image generated by passing the binary data into the cfimage tag can be seen here (in this case, this image contains a link to QR Code

What's Happening Under The Hood?

Obtaining the generated QR Code is incredibly easy. The guys at have engineered their systems to allow anyone to obtain a QR Code by appending the string '.qrcode' to the end of any shortened URL, for example:

Running directly in the browser, you get the generated image returned, which you can then copy / save to suit your needs. The actual call within the CFC Wrapper is very straightforward:

<cffunction name="generateQRCode"
            hint="I take a generated URL, and return the
            binary data of the generated QR Code image.">

    <cfargument name="shortURL"
                required="true" type="string"
                hint="I am a short URL that you wish to
                        create a QR Code for." />
        <cfset var cfhttp         = '' />
        <cfset var returnData     = '' />
                Make the cfhttp request to obtain the image
                (appending the string '.qrcode' onto
                the shortened URL)
            <cfhttp url="#arguments.shortURL#.qrcode" />
            <!--- Successful response? --->
            <cfif cfhttp.StatusCode EQ '200 OK'>
                    Obtain the binary data using the
                    toByteArray() method
                <cfset returnData =
                        cfhttp.fileContent.toByteArray() />

    <cfreturn returnData />


How do I get it?

You can download the revised version of the API wrapper from

comments powered by Disqus