-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_qrcode.py
More file actions
32 lines (28 loc) · 969 Bytes
/
make_qrcode.py
File metadata and controls
32 lines (28 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import qrcode
import logging
from io import BytesIO
from qrcode.image.pil import PilImage
logger = logging.getLogger(__name__)
class MakeQRCode:
@staticmethod
def generate_qr_code(data: str) -> BytesIO:
try:
logger.info("Generating QR code ")
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="transparent", image_factory=PilImage)
img = img.convert("RGBA")
byte_io = BytesIO()
img.save(byte_io, format='PNG')
byte_io.seek(0)
logger.info("QR code generated successfully")
return byte_io
except Exception as e:
logging.error(f"Failed to generate QR code: {e}")
raise