dsh-think-skin 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-think-skin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Reskin the DSH thinking row: your own image, your own words, double random.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"assets/cover.gif",
|
|
32
32
|
"assets/compiled-128",
|
|
33
33
|
"assets/ClaudeCode/verbs.json",
|
|
34
|
-
"assets/ClaudeCode/placeholder.png"
|
|
34
|
+
"assets/ClaudeCode/placeholder.png",
|
|
35
|
+
"assets/酒狐",
|
|
36
|
+
"tools/compile-pack.py"
|
|
35
37
|
],
|
|
36
38
|
"dsh": {
|
|
37
39
|
"bundle": {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Recompile a pack's images at 128px, keeping every frame and its delay.
|
|
2
|
+
|
|
3
|
+
The rule this file exists to protect: **never rewrite per-frame timing.** A GIF
|
|
4
|
+
carries its own cadence — the fish sources run at 20 ms per frame, the fox at
|
|
5
|
+
100 ms. Forcing a fixed frame rate is what made the fox spin twice too fast and
|
|
6
|
+
cost the fish two thirds of its frames.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
python tools/compile-pack.py --pack 蓝色大肥鱼 --source assets/蓝色大肥鱼
|
|
10
|
+
python tools/compile-pack.py --pack 酒狐 --source assets/酒狐
|
|
11
|
+
python tools/compile-pack.py --pack 蓝色大肥鱼 --source ... --dry-run
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import io
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from PIL import Image, ImageSequence
|
|
23
|
+
except ImportError:
|
|
24
|
+
sys.exit("需要 Pillow:pip install pillow")
|
|
25
|
+
|
|
26
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
27
|
+
ROOT = os.path.dirname(HERE)
|
|
28
|
+
BOX = (128, 128)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def store_root():
|
|
32
|
+
home = os.environ.get("DSH_HOME") or os.path.join(os.path.expanduser("~"), ".dsh")
|
|
33
|
+
return os.path.join(home, "storages", "think_skin")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def action_of(filename):
|
|
37
|
+
"""`蓝色大肥鱼_思考(认真地)_2026-08-18-14-37-25.gif` -> `思考(认真地)`."""
|
|
38
|
+
stem = os.path.splitext(os.path.basename(filename))[0]
|
|
39
|
+
stem = re.sub(r"_\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}$", "", stem)
|
|
40
|
+
stem = re.sub(r"^[^_]+_", "", stem)
|
|
41
|
+
return stem.strip()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def compile_gif(src, dst):
|
|
45
|
+
"""Resize every frame to fit BOX, preserving the frame count and delays."""
|
|
46
|
+
im = Image.open(src)
|
|
47
|
+
frames = []
|
|
48
|
+
durations = []
|
|
49
|
+
for frame in ImageSequence.Iterator(im):
|
|
50
|
+
durations.append(frame.info.get("duration", 100) or 100)
|
|
51
|
+
rgba = frame.convert("RGBA")
|
|
52
|
+
w, h = rgba.size
|
|
53
|
+
scale = min(BOX[0] / w, BOX[1] / h)
|
|
54
|
+
size = (max(1, int(round(w * scale))), max(1, int(round(h * scale))))
|
|
55
|
+
scaled = rgba.resize(size, Image.LANCZOS)
|
|
56
|
+
canvas = Image.new("RGBA", BOX, (0, 0, 0, 0))
|
|
57
|
+
canvas.paste(scaled, ((BOX[0] - size[0]) // 2, (BOX[1] - size[1]) // 2), scaled)
|
|
58
|
+
frames.append(canvas)
|
|
59
|
+
frames[0].save(
|
|
60
|
+
dst,
|
|
61
|
+
save_all=True,
|
|
62
|
+
append_images=frames[1:],
|
|
63
|
+
duration=durations,
|
|
64
|
+
loop=0,
|
|
65
|
+
disposal=2,
|
|
66
|
+
optimize=True,
|
|
67
|
+
)
|
|
68
|
+
return len(frames), sum(durations)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main():
|
|
72
|
+
parser = argparse.ArgumentParser()
|
|
73
|
+
parser.add_argument("--pack", required=True, help="pack id in pack.json")
|
|
74
|
+
parser.add_argument("--source", required=True, help="directory of original GIFs")
|
|
75
|
+
parser.add_argument("--dry-run", action="store_true")
|
|
76
|
+
args = parser.parse_args()
|
|
77
|
+
|
|
78
|
+
manifest_path = os.path.join(store_root(), "pack.json")
|
|
79
|
+
document = json.load(io.open(manifest_path, encoding="utf-8"))
|
|
80
|
+
pack = next((p for p in document["packs"] if p["id"] == args.pack), None)
|
|
81
|
+
if pack is None:
|
|
82
|
+
sys.exit("pack.json 里没有 " + args.pack)
|
|
83
|
+
|
|
84
|
+
sources = {}
|
|
85
|
+
for name in os.listdir(args.source):
|
|
86
|
+
path = os.path.join(args.source, name)
|
|
87
|
+
if os.path.splitext(name)[1].lower() != ".gif":
|
|
88
|
+
continue
|
|
89
|
+
sources[action_of(name)] = path
|
|
90
|
+
|
|
91
|
+
print("源目录 %d 个 GIF,清单 %d 张图" % (len(sources), len(pack["images"])))
|
|
92
|
+
before = 0
|
|
93
|
+
after = 0
|
|
94
|
+
missing = []
|
|
95
|
+
for image in pack["images"]:
|
|
96
|
+
target = os.path.join(store_root(), "images", image["file"].replace("/", os.sep))
|
|
97
|
+
if os.path.exists(target):
|
|
98
|
+
before += os.path.getsize(target)
|
|
99
|
+
src = sources.get(image.get("name", ""))
|
|
100
|
+
if src is None:
|
|
101
|
+
missing.append(image.get("name", "?"))
|
|
102
|
+
continue
|
|
103
|
+
if args.dry_run:
|
|
104
|
+
continue
|
|
105
|
+
frames, total = compile_gif(src, target)
|
|
106
|
+
after += os.path.getsize(target)
|
|
107
|
+
print(" %-16s %3d 帧 %.2fs %4d KB" % (
|
|
108
|
+
image.get("name", "")[:16], frames, total / 1000, os.path.getsize(target) // 1024))
|
|
109
|
+
|
|
110
|
+
if missing:
|
|
111
|
+
print("没找到源文件: " + ", ".join(missing))
|
|
112
|
+
if not args.dry_run:
|
|
113
|
+
print("合计 %.2f MB → %.2f MB" % (before / 1024 / 1024, after / 1024 / 1024))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
main()
|