Lua Requires Chilkat v11.7.0+
Lua
QR Code with Binary Data
See more QR Code Examples
Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- The bytes to encode. Here they come from hex, but they could be loaded from a file with LoadFile.
local bd = chilkat.BinData.new()
local success = bd:append_encoded("000102030405FF00FE4368696C6B6174", "hex")
if not success then
print(bd.last_error_text)
return
end
local json = chilkat.JsonObject.new()
json:update_string("payload.type", "binary")
json:update_string("payload.base64", bd:get_encoded("base64"))
json:update_string("output.path", "qa_output/qr_binary.png")
json:update_bool("output.overwrite", true)
json:update_string("output.return", "none")
local fmt = chilkat.Formats.new()
local jsonOut = chilkat.JsonObject.new()
success = fmt:qr_code("generate", json, jsonOut)
if not success then
print(fmt.last_error_text)
return
end
print("bytes given: " .. bd.num_bytes)
print("bytes encoded: " .. jsonOut:int_of("symbols[0].payloadBytes"))
print("mode: " .. jsonOut:string_of("symbols[0].selectedEncoding.mode"))
print("QR version: " .. jsonOut:int_of("symbols[0].selectedEncoding.version"))
-- The image written to qa_output/qr_binary.png:
--
-- Sample output:
-- bytes given: 16
-- bytes encoded: 16
-- mode: byte
-- QR version: 2