一、问题(本轮实测)
`draw-ui` 与 `oil-motion` 目录里**各自带一个内嵌 `.git`** ⇒ 上一次提交把它们记成了 **gitlink(子模块指针)**
⇒ 仓库里只存了一个不属于任何远端的 commit id,**别人克隆下来这两份是空的** ✗(`git status` 显示 ` m draw-ui` / ` m oil-motion` = 子模块内容有改动)。
二、处置(可回退)
· 把两处的 `.git` **挪走**(⛔ 不是删除)⇒ `归档/内嵌git-20261008/{draw-ui,oil-motion}.git`;
· `git rm --cached` 掉那两个 gitlink,再 `git add` 两个目录 ⇒ **按正常文件入库**(内容才真的进仓库)。
三、副作用(如实记)
挪走 `.git` 后,这两个技能**不能再原地 `git pull` 取上游更新**(要更新得重新拉一份覆盖);
如需恢复其本地仓库,把 `归档/内嵌git-20261008/` 里的 `.git` 挪回原处即可。
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""检查图片的实际透明度;不会抠图、修改图片或判断构图质量。"""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def inspect_alpha(path):
|
|
with Image.open(path) as im:
|
|
native_alpha = "A" in im.getbands() or "transparency" in im.info
|
|
histogram = im.convert("RGBA").getchannel("A").histogram()
|
|
total = im.width * im.height
|
|
transparent = histogram[0]
|
|
partial = sum(histogram[1:255])
|
|
opaque = histogram[255]
|
|
return {
|
|
"path": str(Path(path).resolve()),
|
|
"mode": im.mode,
|
|
"size": [im.width, im.height],
|
|
"has_alpha_or_transparency_metadata": native_alpha,
|
|
"transparent_pixels": transparent,
|
|
"partial_alpha_pixels": partial,
|
|
"opaque_pixels": opaque,
|
|
"nonopaque_fraction": (transparent + partial) / total,
|
|
"has_visible_content": partial + opaque > 0,
|
|
"transparency_check_passed": native_alpha
|
|
and transparent + partial > 0
|
|
and partial + opaque > 0,
|
|
}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("image", type=Path)
|
|
parser.add_argument("--require-transparency", action="store_true")
|
|
args = parser.parse_args()
|
|
result = inspect_alpha(args.image)
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
if args.require_transparency and not result["transparency_check_passed"]:
|
|
return 2
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|