Skip to main content

%SYS.QRCode

abstract class %SYS.QRCode extends %SYSTEM.Help

This class contains methods which will allow you to generate a QR Code, and either store it in a file, or return an image of it. The following QR Code image was created by this class, and then embedded in this web page:



See the Wikipedia article at http://en.wikipedia.org/wiki/QR_code for more information about QR Codes.

See also the Wikipedia article at http://en.wikipedia.org/wiki/URI_scheme for more information about URI QR encoding schemes.

This method is not supported on VMS platforms and will return an error if called.


Method Inventory

Parameters

parameter QRMIMETYPE = data:image/png;
Describes the mime type of the file the .dll/.so returns. f.e. data:image/png

Methods

classmethod GenerateFile(QRString As %String, ByRef Filename As %SysPath = "", Dimension As %Integer = 200, CorrectionLevel As %String = "H") as %Status
Generate a QR Code image in a file.
Given a string, this method will generate a QR Code from the string, and write the image of it to the passed in file name in PNG format.

Parameters:

QRString - String from which to generate the QR Code image from.
Filename - (by ref) File where the image is written.
If filename is passed as a null string, then a temporary file is created with the QR Code image written to it, and the name of the file is returned in Filename. If a Filename is passed in, and the file already exists, the file will be overwritten.
Dimension - (default 200) Size in pixels of how large the image should be. If 100 is passed in, an image 100 x 100 pixels is generated. If the image will not fit in the Dimension specified, then the dimension will be increased to an appropriate size.
CorrectionLevel - (default "H") One of the following levels of correction (image quality).
"L" - Low 7% of codewords can be restored.
"M" - Medium 15% of codewords can be restored.
"Q" - Quartile 25% of codewords can be restored.
"H" - High 30% of codewords can be restored.

Notes:
This method requires the %System_CallOut:USE resource to run.

The string is encoded in UTF-8 before the image is generated.

The CorrectionLevel specified partially determines the maximum length of the QRString which can be encoded. The second factor is the encoding tier. There are 4 encoding tiers. "A" is part of the alphanumeric tier while "a" is not. The following is a table of the maximum length for the "alphanumeric" encoding tier for each Correction Level:
L - 4,296
M - 3,391
Q - 2,420
H - 1,852

String size limits for UTF8 encode https://www.qrcode.com/en/about/version.html:
H quality: Numeric 3057 Alpha numeric 1852 UTF8 1273 Kanji 784
Q quality: Numeric 3993 Alpha numeric 2420 UTF8 1663 Kanji 1024
M quality: Numeric 5596 Alpha numeric 3391 UTF8 2331 Kanji 1435
L quality: Numeric 7089 Alpha numeric 4296 UTF8 2953 Kanji 1817
Examples:

Generate a QR Code image in a file which when read directs your browser to the InterSystems web site.

Set x=##Class(%SYS.QRCode).GenerateFile("http://www.intersystems.com","intersystems.png")



Generate a QRCode Image in a file which when read generates an e-mail to the InterSystems support team:

Set x=##Class(%SYS.QRCode).GenerateFile("mailto:support@intersystems.com?subject=A%20QR%20Code%20Test&body=This%20is%20a%20QR%20Code%20Test.%20%0A","support.png")

classmethod GenerateImage(QRString As %String, ByRef QRImage As %Binary, ByRef QRDataURI As %String, Dimension As %Integer = 800, CorrectionLevel As %String = "H") as %Status
Generate a QR Code image in a binary string.
Given a string, this method will generate a QR Code from the string, and store the binary representation of it in a string.

Parameters:

QRString - String from which to generate the QR Code image from.
QRImage (by ref) - Returned binary representation of the created image in PNG format.
QRDataURI (by ref) - Encoded representation of the created image, suitable to be displayed in an HTML Data URI control.
Dimension - (default 200) Size in pixels of how large the image should be. If 100 is passed in, an image 100 x 100 pixels is generated.
CorrectionLevel - (default "H") One of the following levels of correction (image quality).
"L" - Low, 7% of codewords can be restored.
"M" - Medium, 15% of codewords can be restored.
"Q" - Quartile, 25% of codewords can be restored.
"H" - High, 30% of codewords can be restored.

Notes:
This method requires the %System_CallOut:USE resource to run.

The string is encoded in UTF-8 before the image is generated.

The CorrectionLevel specified partially determines the maximum length of the QRString which can be encoded. The second factor is the encoding tier. There are 4 encoding tiers. "A" is part of the alphanumeric tier while "a" is not. The following is a table of the maximum length for the "alphanumeric" encoding tier for each Correction Level:
L - 4,296
M - 3,391
Q - 2,420
H - 1,852

String size limits for UTF8 encode https://www.qrcode.com/en/about/version.html:
H quality: Numeric 3057 Alpha numeric 1852 UTF8 1273 Kanji 784
Q quality: Numeric 3993 Alpha numeric 2420 UTF8 1663 Kanji 1024
M quality: Numeric 5596 Alpha numeric 3391 UTF8 2331 Kanji 1435
L quality: Numeric 7089 Alpha numeric 4296 UTF8 2953 Kanji 1817


The QRDataURI value returned is in the format:

"data:image/png;base64,"_Base64Encode(QRImage)

It can be displayed as an image in a ZEN page with the following ZEN control:

image id="QRCode" width="200" height="200" src=""

and then setting the src parameter as follows:

s Status=##Class(%SYS.QRCode).GenerateImage(String,,.DataURI)
Set ..%GetComponentById("QRCode").src = DataURI

Inherited Members

Inherited Methods

FeedbackOpens in a new tab