adding the logic to generate the image
This commit is contained in:
19
backend/app/services/qr_service.py
Normal file
19
backend/app/services/qr_service.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from io import BytesIO
|
||||
|
||||
import qrcode
|
||||
|
||||
|
||||
def generate_qr_image_bytes(text: str, size: int = 300) -> bytes:
|
||||
img = qrcode.make(text)
|
||||
|
||||
# Ensure RGB for consistent PNG output
|
||||
if getattr(img, "mode", None) != "RGB":
|
||||
img = img.convert("RGB")
|
||||
|
||||
if size:
|
||||
img = img.resize((size, size))
|
||||
|
||||
buf = BytesIO()
|
||||
img.save(buf, "PNG")
|
||||
buf.seek(0)
|
||||
return buf.getvalue()
|
||||
Reference in New Issue
Block a user