Lua Requires Chilkat v11.7.0+
Lua
Generate a QR Code as SVG
See more QR Code Examples
Demonstrates SVG output. An SVG is a vector image, so it stays sharp at any size, which suits print and responsive web pages. Setting output.format to svg and output.return to text returns the SVG document as a string in outputs[0].text. The SVG can also be written straight to a file with output.path, the same as a PNG.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.
local json = chilkat.JsonObject.new()
json:update_string("payload.text", "https://www.chilkatsoft.com/")
json:update_string("output.format", "svg")
-- An SVG is text, so it can be returned as text rather than as base64.
json:update_string("output.return", "text")
local fmt = chilkat.Formats.new()
local jsonOut = chilkat.JsonObject.new()
local success = fmt:qr_code("generate", json, jsonOut)
if not success then
print(fmt.last_error_text)
return
end
local sbSvg = chilkat.StringBuilder.new()
jsonOut:string_of_sb("outputs[0].text", sbSvg)
print("MIME type: " .. jsonOut:string_of("outputs[0].mimeType"))
print("size: " .. jsonOut:int_of("outputs[0].width") .. " x " .. jsonOut:int_of("outputs[0].height") .. " " .. jsonOut:string_of("outputs[0].units"))
print("SVG length: " .. sbSvg.length .. " characters")
-- The SVG is a complete document that can be saved, or placed inline in an HTML page.
success = sbSvg:write_file("qa_output/qr_chilkat.svg", "utf-8", false)
if not success then
print(sbSvg.last_error_text)
return
end
-- The SVG:
--
-- Sample output:
-- MIME type: image/svg+xml
-- size: 148 x 148 px
-- SVG length: 12500 characters