19 lines
353 B
Python
19 lines
353 B
Python
from io import BytesIO
|
|
|
|
import qrcode
|
|
|
|
|
|
def generate_qr_image_bytes(text: str, size: int = 300) -> bytes:
|
|
img = qrcode.make(text)
|
|
|
|
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()
|