fix: 钉钉桌面端通知二维码被裁剪

桌面端钉钉会把 Markdown 图片裁成横向区域,正方形二维码上下被裁掉。
二维码居中放到 3:2 白底画布上;网页中的二维码图片改用 object-fit 避免拉伸。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-23 10:44:35 +09:00
co-authored by Claude Opus 5.5
parent 8f2f23682f
commit 6890f13aa9
4 changed files with 25 additions and 4 deletions
+17 -1
View File
@@ -454,6 +454,22 @@ def _upload_oss(config: dict, files: list[tuple[Path, str]]) -> dict[str, str]:
return urls
# 桌面端钉钉会把 Markdown 图片裁成约 1.4:1 的横向区域,正方形二维码上下被裁掉
# (手机端完整显示)。居中放到 3:2 的白底画布上:桌面端裁掉的只是空白,
# 手机端二维码仍占图片宽度的 2/3,不至于太小。
_QR_CANVAS_RATIO = 1.5
def _pad_to_wide(image):
from PIL import Image
image = image.convert("RGB")
width, height = image.size
canvas = Image.new("RGB", (round(height * _QR_CANVAS_RATIO), height), "white")
canvas.paste(image, ((canvas.width - width) // 2, 0))
return canvas
def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str]:
"""发布 IPA,返回下载 URL 与二维码公开 URL。"""
upload = config.get("_upload_config", {})
@@ -487,7 +503,7 @@ def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str
qr = qrcode.QRCode(box_size=5, border=4)
qr.add_data(urls[".html"])
qr.make(fit=True)
qr.make_image(fill_color="black", back_color="white").save(qr_path)
_pad_to_wide(qr.make_image(fill_color="black", back_color="white").get_image()).save(qr_path)
urls.update(uploader(upload, [(qr_path, qr_remote)]))
return urls[".html"], urls[".png"]