Files
konova/konova/utils/qrcode.py
T
mpeltriaux 62e02d745f # QRCode fix
* fixes bug where svg qr code would not be created properly since an upgrade of the package
2026-03-01 14:30:30 +01:00

50 lines
1.1 KiB
Python

"""
Author: Michel Peltriaux
Created on: 14.12.25
"""
from io import BytesIO
import qrcode
import qrcode.image.svg as svg
class QrCode:
""" A wrapping class for creating a qr code with content
"""
_content = None
_img = None
def __init__(self, content: str, size: int):
self._content = content
self._img = self._generate_qr_code(content, size)
def _generate_qr_code(self, content: str, size: int = 20) -> str:
""" Generates a qr code from given content
Args:
content (str): The content for the qr code
size (int): The image size
Returns:
qrcode_svg (str): The qr code as svg
"""
qr = qrcode.QRCode(
image_factory=qrcode.image.svg.SvgPathImage,
box_size=size
)
qr.add_data(content)
qr.make(
fit=True
)
img = qr.make_image()
return img.to_string(encoding="unicode")
def get_img(self):
return self._img
def get_content(self):
return self._content