chore: fork from IRIS track 供 LICA 部门独立运行
- 复制来源: /home/yueli/track @ 192c8ee (feature/ai-audit-update) - 组织隔离目标: LICA - 端口规划: 前端 8030 / 后端 8031 / 数据库 8032 - 已排除 deploy.sh、deploy_full.sh、docker-compose.prod.yml(IRIS 生产发布脚本) - 已排除工作区未提交改动,取干净的 192c8ee 状态
This commit is contained in:
34
backend/app/services/qrcode_service.py
Normal file
34
backend/app/services/qrcode_service.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""二维码生成服务 — 参考 MOM 系统 label_service.py 的 QR 生成逻辑"""
|
||||
import io
|
||||
import qrcode
|
||||
from qrcode.image.pil import PilImage
|
||||
|
||||
|
||||
def generate_qrcode_png(content: str, size_px: int = 300) -> io.BytesIO:
|
||||
"""
|
||||
生成二维码 PNG 图片,返回 BytesIO 流。
|
||||
|
||||
参数:
|
||||
content: 二维码内容(如 16 位序列号)
|
||||
size_px: 输出图片尺寸(像素),默认 300×300
|
||||
|
||||
返回:
|
||||
io.BytesIO: PNG 格式的图片字节流
|
||||
"""
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
||||
box_size=10,
|
||||
border=2,
|
||||
)
|
||||
qr.add_data(content)
|
||||
qr.make(fit=True)
|
||||
|
||||
img: PilImage = qr.make_image(fill_color="black", back_color="white")
|
||||
img = img.convert("RGB")
|
||||
img = img.resize((size_px, size_px))
|
||||
|
||||
buf = io.BytesIO()
|
||||
img.save(buf, format="PNG")
|
||||
buf.seek(0)
|
||||
return buf
|
||||
Reference in New Issue
Block a user