@reconcrap/boss-recommend-mcp 1.2.2 → 1.2.4

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.
@@ -1,141 +1,141 @@
1
- #!/usr/bin/env python
2
- """
3
- Stitch vertically captured resume chunks into one full-length image.
4
-
5
- Usage:
6
- python stitch_resume_chunks.py <metadata.json> <output.png>
7
- """
8
-
9
- from __future__ import annotations
10
-
11
- import json
12
- import math
13
- import os
14
- import sys
15
- from typing import Any, Dict, List, Tuple
16
-
17
- from PIL import Image
18
-
19
-
20
- def _clamp(value: int, low: int, high: int) -> int:
21
- return max(low, min(high, value))
22
-
23
-
24
- def _load_chunks(metadata_path: str) -> List[Dict[str, Any]]:
25
- with open(metadata_path, "r", encoding="utf-8") as f:
26
- meta = json.load(f)
27
-
28
- chunks = meta.get("chunks", [])
29
- if not isinstance(chunks, list) or not chunks:
30
- raise ValueError("No chunks found in metadata.")
31
-
32
- cleaned = []
33
- for idx, chunk in enumerate(chunks):
34
- file_path = chunk.get("file")
35
- if not file_path or not os.path.exists(file_path):
36
- raise FileNotFoundError(f"Chunk image missing: {file_path}")
37
- cleaned.append(
38
- {
39
- "index": int(chunk.get("index", idx)),
40
- "file": file_path,
41
- "scroll_top": float(chunk.get("scrollTop", 0.0)),
42
- "clip_h_css": float(chunk.get("clipHeightCss", 0.0)),
43
- }
44
- )
45
-
46
- cleaned.sort(key=lambda x: (x["scroll_top"], x["index"]))
47
- return cleaned
48
-
49
-
50
- def stitch(metadata_path: str, output_path: str) -> Dict[str, Any]:
51
- chunks = _load_chunks(metadata_path)
52
-
53
- opened: List[Tuple[Dict[str, Any], Image.Image]] = []
54
- for chunk in chunks:
55
- img = Image.open(chunk["file"]).convert("RGB")
56
- opened.append((chunk, img))
57
-
58
- try:
59
- segments: List[Image.Image] = []
60
- used: List[Dict[str, Any]] = []
61
- prev_chunk = None
62
-
63
- for chunk, img in opened:
64
- if prev_chunk is None:
65
- segments.append(img.copy())
66
- used.append(
67
- {
68
- "file": chunk["file"],
69
- "scrollTop": chunk["scroll_top"],
70
- "cropTopPx": 0,
71
- "keptHeightPx": img.height,
72
- }
73
- )
74
- prev_chunk = chunk
75
- continue
76
-
77
- delta_css = chunk["scroll_top"] - prev_chunk["scroll_top"]
78
- if delta_css <= 0.5:
79
- prev_chunk = chunk
80
- continue
81
-
82
- clip_h_css = chunk["clip_h_css"] if chunk["clip_h_css"] > 1 else prev_chunk["clip_h_css"]
83
- ratio = (img.height / clip_h_css) if clip_h_css > 1 else 1.0
84
- new_pixels = int(round(delta_css * ratio))
85
- new_pixels = _clamp(new_pixels, 1, img.height)
86
- crop_top = img.height - new_pixels
87
- crop_top = _clamp(crop_top, 0, img.height - 1)
88
-
89
- seg = img.crop((0, crop_top, img.width, img.height))
90
- segments.append(seg)
91
- used.append(
92
- {
93
- "file": chunk["file"],
94
- "scrollTop": chunk["scroll_top"],
95
- "cropTopPx": crop_top,
96
- "keptHeightPx": seg.height,
97
- }
98
- )
99
- prev_chunk = chunk
100
-
101
- out_width = max(seg.width for seg in segments)
102
- out_height = sum(seg.height for seg in segments)
103
- out = Image.new("RGB", (out_width, out_height), color=(255, 255, 255))
104
-
105
- y = 0
106
- for seg in segments:
107
- out.paste(seg, (0, y))
108
- y += seg.height
109
-
110
- out.save(output_path, format="PNG")
111
-
112
- return {
113
- "output": os.path.abspath(output_path),
114
- "segments": len(segments),
115
- "size": {"width": out_width, "height": out_height},
116
- "used": used,
117
- }
118
- finally:
119
- for _, img in opened:
120
- img.close()
121
-
122
-
123
- def main() -> None:
124
- if len(sys.argv) != 3:
125
- print("Usage: python stitch_resume_chunks.py <metadata.json> <output.png>", file=sys.stderr)
126
- sys.exit(1)
127
-
128
- metadata_path = os.path.abspath(sys.argv[1])
129
- output_path = os.path.abspath(sys.argv[2])
130
-
131
- try:
132
- result = stitch(metadata_path, output_path)
133
- print(json.dumps(result, ensure_ascii=False, indent=2))
134
- except Exception as exc:
135
- print(f"[stitch] failed: {exc}", file=sys.stderr)
136
- sys.exit(1)
137
-
138
-
139
- if __name__ == "__main__":
140
- main()
141
-
1
+ #!/usr/bin/env python
2
+ """
3
+ Stitch vertically captured resume chunks into one full-length image.
4
+
5
+ Usage:
6
+ python stitch_resume_chunks.py <metadata.json> <output.png>
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import math
13
+ import os
14
+ import sys
15
+ from typing import Any, Dict, List, Tuple
16
+
17
+ from PIL import Image
18
+
19
+
20
+ def _clamp(value: int, low: int, high: int) -> int:
21
+ return max(low, min(high, value))
22
+
23
+
24
+ def _load_chunks(metadata_path: str) -> List[Dict[str, Any]]:
25
+ with open(metadata_path, "r", encoding="utf-8") as f:
26
+ meta = json.load(f)
27
+
28
+ chunks = meta.get("chunks", [])
29
+ if not isinstance(chunks, list) or not chunks:
30
+ raise ValueError("No chunks found in metadata.")
31
+
32
+ cleaned = []
33
+ for idx, chunk in enumerate(chunks):
34
+ file_path = chunk.get("file")
35
+ if not file_path or not os.path.exists(file_path):
36
+ raise FileNotFoundError(f"Chunk image missing: {file_path}")
37
+ cleaned.append(
38
+ {
39
+ "index": int(chunk.get("index", idx)),
40
+ "file": file_path,
41
+ "scroll_top": float(chunk.get("scrollTop", 0.0)),
42
+ "clip_h_css": float(chunk.get("clipHeightCss", 0.0)),
43
+ }
44
+ )
45
+
46
+ cleaned.sort(key=lambda x: (x["scroll_top"], x["index"]))
47
+ return cleaned
48
+
49
+
50
+ def stitch(metadata_path: str, output_path: str) -> Dict[str, Any]:
51
+ chunks = _load_chunks(metadata_path)
52
+
53
+ opened: List[Tuple[Dict[str, Any], Image.Image]] = []
54
+ for chunk in chunks:
55
+ img = Image.open(chunk["file"]).convert("RGB")
56
+ opened.append((chunk, img))
57
+
58
+ try:
59
+ segments: List[Image.Image] = []
60
+ used: List[Dict[str, Any]] = []
61
+ prev_chunk = None
62
+
63
+ for chunk, img in opened:
64
+ if prev_chunk is None:
65
+ segments.append(img.copy())
66
+ used.append(
67
+ {
68
+ "file": chunk["file"],
69
+ "scrollTop": chunk["scroll_top"],
70
+ "cropTopPx": 0,
71
+ "keptHeightPx": img.height,
72
+ }
73
+ )
74
+ prev_chunk = chunk
75
+ continue
76
+
77
+ delta_css = chunk["scroll_top"] - prev_chunk["scroll_top"]
78
+ if delta_css <= 0.5:
79
+ prev_chunk = chunk
80
+ continue
81
+
82
+ clip_h_css = chunk["clip_h_css"] if chunk["clip_h_css"] > 1 else prev_chunk["clip_h_css"]
83
+ ratio = (img.height / clip_h_css) if clip_h_css > 1 else 1.0
84
+ new_pixels = int(round(delta_css * ratio))
85
+ new_pixels = _clamp(new_pixels, 1, img.height)
86
+ crop_top = img.height - new_pixels
87
+ crop_top = _clamp(crop_top, 0, img.height - 1)
88
+
89
+ seg = img.crop((0, crop_top, img.width, img.height))
90
+ segments.append(seg)
91
+ used.append(
92
+ {
93
+ "file": chunk["file"],
94
+ "scrollTop": chunk["scroll_top"],
95
+ "cropTopPx": crop_top,
96
+ "keptHeightPx": seg.height,
97
+ }
98
+ )
99
+ prev_chunk = chunk
100
+
101
+ out_width = max(seg.width for seg in segments)
102
+ out_height = sum(seg.height for seg in segments)
103
+ out = Image.new("RGB", (out_width, out_height), color=(255, 255, 255))
104
+
105
+ y = 0
106
+ for seg in segments:
107
+ out.paste(seg, (0, y))
108
+ y += seg.height
109
+
110
+ out.save(output_path, format="PNG")
111
+
112
+ return {
113
+ "output": os.path.abspath(output_path),
114
+ "segments": len(segments),
115
+ "size": {"width": out_width, "height": out_height},
116
+ "used": used,
117
+ }
118
+ finally:
119
+ for _, img in opened:
120
+ img.close()
121
+
122
+
123
+ def main() -> None:
124
+ if len(sys.argv) != 3:
125
+ print("Usage: python stitch_resume_chunks.py <metadata.json> <output.png>", file=sys.stderr)
126
+ sys.exit(1)
127
+
128
+ metadata_path = os.path.abspath(sys.argv[1])
129
+ output_path = os.path.abspath(sys.argv[2])
130
+
131
+ try:
132
+ result = stitch(metadata_path, output_path)
133
+ print(json.dumps(result, ensure_ascii=False, indent=2))
134
+ except Exception as exc:
135
+ print(f"[stitch] failed: {exc}", file=sys.stderr)
136
+ sys.exit(1)
137
+
138
+
139
+ if __name__ == "__main__":
140
+ main()
141
+