mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
* 🐛 插入新的Schedulable时应传入use_batch参数 * ✨ 适配ceobecanteen平台 Co-authored-by: phidiaLam <2957035701@qq.com> * ✨ ✨ 明日方舟公告与官网采用截图分享 (#480) * ✨ 明日方舟公告与官网采用截图分享 * 💄 auto fix by pre-commit hooks * 🐛 修复缺少的导入,优化逻辑 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Azide <rukuy@qq.com> * 🐛 优化截图图片效果 * 🐛 修复错误将转发内图片视作头图的问题 * 🍱 使用正式 Bison Logo * 💄 auto fix by pre-commit hooks * 🐛 请求小刻API时不在headers里添加过多字段 * 🐛 get_comb_id方法删除无用的targets参数 * 💡 get_comb_id方法更新注释 * 🔥 移除发送部分的更改 * ✨ 在命名中明确表示cond_func意图 * ♻️ 拆分get_comb_id功能 * ♻️ 调整缓存逻辑 * ✨ 使用uri在theme中调用platform截图 * ♻️ 重构截图逻辑 * ✨ 添加模糊匹配提示 * ✨ 适配新版Site * 💄 auto fix by pre-commit hooks * 🐛 去掉不必要的排序 * 🐛 修正不应出现的驼峰变量名 * ♻️ 按review意见修改 * ♻️ 调整截图函数逻辑 * 🔊 调低日志等级 * ✏️ 修复一些拼写和格式 --------- Co-authored-by: phidiaLam <2957035701@qq.com> Co-authored-by: 洛梧藤 <67498817+phidiaLam@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from io import BytesIO
|
|
from pathlib import Path
|
|
from base64 import b64encode
|
|
|
|
from qrcode import constants
|
|
from qrcode.main import QRCode
|
|
from qrcode.image.pil import PilImage
|
|
|
|
|
|
def convert_to_qr(data: str, **kwarg) -> bytes:
|
|
"""Convert data to QR code
|
|
Args:
|
|
data (str): data to be converted
|
|
Returns:
|
|
bytes: QR code image
|
|
"""
|
|
qr = QRCode(
|
|
version=1,
|
|
error_correction=constants.ERROR_CORRECT_L,
|
|
box_size=10,
|
|
border=2,
|
|
image_factory=PilImage,
|
|
)
|
|
qr.add_data(data)
|
|
qr.make(fit=True)
|
|
f = BytesIO()
|
|
qr.make_image(**kwarg).save(f)
|
|
return f.getvalue()
|
|
|
|
|
|
def web_embed_image(pic_data: bytes | Path | BytesIO, *, ext: str = "png"):
|
|
"""将图片数据转换为Base64编码的Data URI"""
|
|
match pic_data:
|
|
case bytes():
|
|
pic_bytes = pic_data
|
|
case Path():
|
|
pic_bytes = Path(pic_data).read_bytes()
|
|
case BytesIO():
|
|
pic_bytes = pic_data.getvalue()
|
|
case _:
|
|
raise TypeError("pic_data must be bytes, Path or BytesIO")
|
|
return f"data:image/{ext};base64,{b64encode(pic_bytes).decode()}"
|