Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ee89562

Browse files
committed
Allow specifying the min and max version number in qrCreate
1 parent 70b77b2 commit ee89562

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

extensions/script-libraries/qr/qr.livecodescript

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,35 @@ Create a QR code
14361436
Example:
14371437
qrCreate "MyImage", "QR data", "M", 3
14381438
1439+
Example:
1440+
--creating QR Code with ECC level M, Size 3, Mask 7 and version 14
1441+
qrCreate "MyImage", "QR data", "M", 3, 7, 14, 14
1442+
1443+
Example:
1444+
-- example how to use qrCreate with LiveCode server
1445+
qrCreate "!", tData, tECC, tSize
1446+
put the result into tData
1447+
if tData begins with "Error" then
1448+
put tData
1449+
else
1450+
# line 1 of the result contains some info
1451+
# the remaining lines contain the png image data
1452+
put line 1 of tData into tInfo
1453+
delete line 1 of tData
1454+
1455+
put "<b>Qr code info</b><br/>" & LF
1456+
put "Version: " & item 1 of tInfo & "<br/>" & LF
1457+
put "ECC: " & item 2 of tInfo & "<br/>" & LF
1458+
put "Mode: " & item 3 of tInfo & "<br/>" & LF
1459+
put "Mask: " & item 4 of tInfo & "<br/>" & LF
1460+
1461+
# show the image
1462+
put base64Encode(tData) into tData
1463+
replace LF with empty in tData
1464+
put "<img src='data:image/png;base64," & tData & "'/><br/>" & LF
1465+
end if
1466+
1467+
14391468
Description:
14401469
Set the text of an image to a QR code or get the PMG data of the QR code image.
14411470
@@ -1466,6 +1495,14 @@ Each mask pattern changes the bits according to their coordinates in
14661495
the QR matrix. The purpose of a mask pattern is to make the QR code
14671496
easier for a QR scanner to read.
14681497
1498+
pMinVersion:
1499+
An integer value between 1 and 40. It must be lower or equal to pMaxVersion.
1500+
If pMinVersion is not specified then the default value of 1 is used.
1501+
1502+
pMaxVersion:
1503+
An integer value between 1 and 40. It must be higher or equal to pMaxVersion.
1504+
If pMaxVersion is not specified then the default value of 40 is used.
1505+
14691506
The result:
14701507
If successful, the first line of the result will be the following values:
14711508
- QR version
@@ -1483,7 +1520,7 @@ with LiveCode server to generate QR codes on web pages.
14831520
14841521
*/
14851522

1486-
command qrCreate pImg, pData, pECC, pSize, pMask
1523+
command qrCreate pImg, pData, pECC, pSize, pMask, pMinVersion, pMaxVersion
14871524
lock screen
14881525

14891526
try
@@ -1522,7 +1559,13 @@ command qrCreate pImg, pData, pECC, pSize, pMask
15221559
# calculate minimum version required
15231560
local tMinVersion
15241561
put 0 into tMinVersion
1525-
repeat with tVersion = 1 to 40
1562+
1563+
if pMinVersion is empty then put 1 into pMinVersion
1564+
if pMaxVersion is empty then put 40 into pMaxVersion
1565+
if pMaxVersion > 40 or pMaxVersion < 1 or pMinVersion < 1 or pMinVersion >40 then throw "allowed values for pMinVersion to pMaxVersion are 1 to 40"
1566+
if pMinVersion >pMaxVersion then throw "pMinversion must be lower or equal to pMaxVersion"
1567+
1568+
repeat with tVersion = pMinVersion to pMaxVersion
15261569
local tCCIBits, tBitStreamLength, tErrorWords, tTotalWords, tBitStreamMax, tRemBits
15271570
put 0 into tCCIBits -- character count indicator
15281571
put 0 into tBitStreamLength

0 commit comments

Comments
 (0)