# QR code

* refactors qr code generating into class
* refactors usage of former qr code method calls
This commit is contained in:
2025-12-14 16:43:31 +01:00
parent e4c459f92e
commit a2bda8d230
6 changed files with 100 additions and 58 deletions

47
konova/utils/qrcode.py Normal file
View File

@@ -0,0 +1,47 @@
"""
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
"""
img_factory = svg.SvgImage
qrcode_img = qrcode.make(
content,
image_factory=img_factory,
box_size=size
)
stream = BytesIO()
qrcode_img.save(stream)
return stream.getvalue().decode()
def get_img(self):
return self._img
def get_content(self):
return self._content