Template
27 lines
721 B
Python
27 lines
721 B
Python
"""Генерация QR (SVG) без Pillow — только пакет qrcode."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
|
|
import qrcode
|
|
import qrcode.image.svg
|
|
|
|
|
|
def make_qr_svg(data: str, *, scale: int = 4, border: int = 2) -> bytes:
|
|
"""Возвращает SVG QR как bytes (image/svg+xml)."""
|
|
text = (data or "").strip()
|
|
if not text:
|
|
raise ValueError("empty qr data")
|
|
factory = qrcode.image.svg.SvgPathImage
|
|
img = qrcode.make(
|
|
text,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
|
box_size=max(2, int(scale)),
|
|
border=max(1, int(border)),
|
|
image_factory=factory,
|
|
)
|
|
buf = io.BytesIO()
|
|
img.save(buf)
|
|
return buf.getvalue()
|