app.qrcode - QR Code API
QR code generation and recognition.
Generation
app.qrcode.generate(text, config?)
Generate a QR code image.
Parameters:
text(string) - text to encodeconfig(table):path(string, required) - output image pathsize(number, optional) - image size, default 256correctionLevel(string, optional) - error correction level:"L","M"(default),"Q","H"color(string, optional) - foreground color,"#RRGGBB"formatbackgroundColor(string, optional) - background color,"#RRGGBB"format
Returns: boolean, error
-- Basic generation
app.qrcode.generate("https://example.com", {
path = "/tmp/qr.png"
})
-- Custom style
app.qrcode.generate("https://example.com", {
path = "/tmp/qr.png",
size = 512,
correctionLevel = "H",
color = "#1A1A2E",
backgroundColor = "#E0E0E0"
})
Recognition
app.qrcode.recognize(imagePath)
Recognize QR codes in an image.
Parameters:
imagePath(string) - image file path
Returns: array<table>, error - each item contains:
text(string) - decoded texttype(string) - type ("QRCode")bounds(table) - position:{x, y, w, h}
local codes, err = app.qrcode.recognize("/path/to/image.png")
if codes then
for _, code in ipairs(codes) do
app.log.info("Content: " .. code.text)
end
end
app.qrcode.recognizeFromScreen(options?)
Capture the screen and recognize QR codes.
Parameters:
options(table, optional):displayId(number) - display IDrect(table) - capture region:{x, y, w, h}
Returns: array<table>, error - same as recognize()
local codes = app.qrcode.recognizeFromScreen()
if codes and #codes > 0 then
app.clipboard.setText(codes[1].text)
app.notification.show("QR Code", "Copied: " .. codes[1].text)
end
Examples
Generate QR Code for Selected File
function MyPlugin:handleGenerateQR(context)
local file = context.selectedFiles[1]
local text = app.dialog.input("Enter content", app.path.basename(file))
if not text then return end
local qrPath = app.path.removeExtension(file) .. "_qr.png"
local ok, err = app.qrcode.generate(text, {
path = qrPath,
size = 512,
correctionLevel = "H"
})
if ok then
app.notification.show("Done", "QR code generated")
app.finder.reveal(qrPath)
else
app.dialog.alert("Error", err or "Generation failed")
end
end
Recognize QR Code in Image
function MyPlugin:handleScanQR(context)
local file = context.selectedFiles[1]
local codes, err = app.qrcode.recognize(file)
if not codes then
app.dialog.alert("Error", err or "Recognition failed")
return
end
if #codes == 0 then
app.dialog.alert("Result", "No QR code found")
return
end
local text = codes[1].text
app.clipboard.setText(text)
app.notification.show("QR Code", "Copied: " .. text)
end