Click here to download the free,

public domain library.

 

 

The sQuiRt library for LiveCode generates QR codes according to the ISO international standard (ISO/IEC18004).

 

'QR Code' is a registered trademark of DENSO WAVE INCORPORATED.

 

 

All versions (1 - 40) and all error correction levels

(L, M, Q, H) are supported.

 

 

Correction levels and approximate error correction capabilities.

Level

Error correction

L 7%
M 15%
Q 25%
H 30%

 

 

As this library is 100% LiveCode, it is suitable for Mac, Windows, Linux, Mobile and  LiveCode server platforms.

 

 

To attach sQuiRt to your project, simply open the library in LiveCode and change it's 'mainStack' property to your stack. You can use the property inspector to do this or the following line of code;

 

set the mainStack of stack "sQuiRt" to "MyStack"

 

Now save your stack and sQuiRt will be saved as a substack. The following commands show an example of using the library.

 

-- add the library to the message path if required

if "sQuiRt" is not among the lines of the stacksInUse then

    start using stack "sQuiRt"

end if

 

-- optionally use colors other than black and white

-- there must be a high enough contrast between colors for scanning
-- the foreground color should be darker than the background color

-- LC color references also work : "0,0,255" instead of "Blue"

qrSetColors "Blue", "Yellow"

 

-- create a QR code

qrCreate "MyImage", "QR data", "M", 3

 

The parameters for the qrCreate command are;

  • "MyImage" - the name of an image object on the card, a filename or the special code "!" which will return the image data in the result.
  • "QR data" - the data to be encoded.
  • "M" - error correction level  (L, M, Q or H).
  • "3" - module size: you can make the code larger/smaller.  You can also just rescale the image after the code has been created.

 

 

The qrCreate command returns information in the result;

  • On success, the first line of the result will be the following values: QR version, ECC, Mode, Mask, Image size with quiet zone (based on module size 1)
  • On failure, the result will contain "Error:" and then an error description.

 

If the special character '!' is used for 'MyImage', then the result also contains the raw output of a png image.  You can use this data, for example, with LiveCode server to generate QR codes on web pages.

 

 

 

 

Example using sQuiRt with LiveCode server

There's an online demo at http://splash21.on-rev.com/index.lc

 

The following is an excerpt from the demo;

 

.....

.....

 

start using stack "sQuiRt.livecode"
qrCreate "!", tData, tECC, tSize
put the result into tData
if tData begins with "Error" then
    put tData
else
    # line 1 of the result contains some info
    # the remaining lines contain the png image data
    put line 1 of tData into tInfo
    delete line 1 of tData
 
    put "<b>Qr code info</b><br/>" & LF
    put "Version: " & item 1 of tInfo & "<br/>" & LF
    put "ECC: " & item 2 of tInfo & "<br/>" & LF
    put "Mode: " & item 3 of tInfo & "<br/>" & LF
    put "Mask: " & item 4 of tInfo & "<br/>" & LF
 
    # show the image
    put base64Encode(tData) into tData
    replace LF with empty in tData
    put "<img src='data:image/png;base64," & tData & "'/><br/>" & LF
end if
.....
.....