cardserver / app /utils /qr_utils.py
GitHub Actions
🚀 Auto-deploy from GitHub
eb803dd
import qrcode
from pathlib import Path
import uuid
# Handle import for both package and direct execution
try:
from ..core.config import settings
except ImportError:
# If relative import fails, try absolute import
try:
from app.core.config import settings
except ImportError:
# Create a minimal settings object if import fails
class MinimalSettings:
QR_CODE_BOX_SIZE = 10
QR_CODE_BORDER = 4
settings = MinimalSettings()
def generate_qr_code_sync(data: str, output_path: Path, size: int) -> str:
"""
Generiert einen QR-Code und speichert ihn.
Gibt die UUID der generierten Datei (ohne Erweiterung) zurück.
Verwendet box_size und border aus den settings.
"""
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=settings.QR_CODE_BOX_SIZE,
border=settings.QR_CODE_BORDER,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
output_path.mkdir(parents=True, exist_ok=True)
file_id = str(uuid.uuid4())
file_path_with_id = output_path / f"{file_id}.png"
img.save(file_path_with_id)
return file_id