qrcode
#
Description#
Plugin to generate and scan QR and bar codes.
Configuration#
qrcode:
# [Optional]
# Name of the plugin that will be used as a camera
# to capture images (e.g. ``camera.cv`` or ``camera.pi``). This is
# required if you want to use the ``start_scanning`` action to scan
# QR codes from a camera.
# camera_plugin: # type=Optional[str]
Triggered events#
Actions#
Module reference#
- class platypush.plugins.qrcode.QrcodePlugin(camera_plugin: str | None = None, **kwargs)[source]#
Bases:
Plugin
Plugin to generate and scan QR and bar codes.
- __init__(camera_plugin: str | None = None, **kwargs)[source]#
- Parameters:
camera_plugin – Name of the plugin that will be used as a camera to capture images (e.g.
camera.cv
orcamera.pi
). This is required if you want to use thestart_scanning
action to scan QR codes from a camera.
- decode(image_file: str) dict [source]#
Decode a QR code from an image file.
- Parameters:
image_file – Path of the image file.
- Returns:
{ "image_file": "/tmp/qr_code.png", "results": "Decoded QR code results" }
- generate(content: str | bytes, binary: bool = False, output_file: str | None = None, show: bool = False, format: str = 'png') dict [source]#
Generate a QR code.
If you configured the
platypush.backend.http.HttpBackend
then you can also generate codes directly from the browser throughhttp://<host>:<port>/qrcode?content=...
.- Parameters:
content – Text, URL or content of the QR code.
binary – If True then the content will be treated as binary data. Content needs to be either a bytes object or a base64-encoded string.
output_file – If set then the QR code will be exported in the specified image file. Otherwise, a base64-encoded representation of its binary content will be returned in the response as
data
.show – If True, and if the device where the application runs has an active display, then the generated QR code will be shown on display.
format – Output image format (default:
png
).
- Returns:
{ "data": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAFyAQAAAADAX2yk", "format": "png", "image_file": "/tmp/qr_code.png", "text": "https://platypush.tech" }
- start_scanning(camera_plugin: str | None = None, duration: float | None = None, n_codes: int | None = None) List[dict] | None [source]#
Decode QR-codes and bar codes using a camera.
- Parameters:
camera_plugin – Camera plugin (overrides default
camera_plugin
).duration – How long the capturing phase should run (default: until
stop_scanning
or app termination).n_codes – Stop after decoding this number of codes (default: None).
- Returns:
[ { "data": "https://platypush.tech", "rect": "Rectangle in the image where the QR code was found", "type": "QRCODE" } ]