@sylphx/image-reader-mcp 0.1.2 → 0.1.5
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.
- package/README.md +5 -3
- package/bin/image-reader-mcp +80 -9
- package/dist/doctor-cli.js +44 -35
- package/package.json +12 -6
- package/src/doctor.ts +22 -3
- package/src/handlers/readImage.ts +40 -2
- package/src/schemas/readImage.ts +16 -2
- package/src/utils/agentMap.ts +1 -0
- package/src/utils/applyImageIntelligence.ts +21 -5
- package/src/utils/layout.ts +50 -3
- package/src/utils/ocr.ts +114 -34
- package/src/utils/optionalLlm.ts +185 -24
- package/src/utils/palette.ts +46 -31
- package/bin/native/image-reader-mcp-server +0 -0
package/src/utils/palette.ts
CHANGED
|
@@ -1,36 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
/** Cheap local palette sample via optional sharp stats (not ML segmentation). */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.padStart(2, '0')
|
|
19
|
-
)
|
|
20
|
-
.join('')}`;
|
|
21
|
-
|
|
22
|
-
const colors: Array<{ hex: string; approx_share: number }> = [
|
|
23
|
-
{ hex: hex(dominant.r, dominant.g, dominant.b), approx_share: 0.55 },
|
|
24
|
-
];
|
|
3
|
+
type SharpLike = (
|
|
4
|
+
input: string,
|
|
5
|
+
opts?: { failOn?: string }
|
|
6
|
+
) => {
|
|
7
|
+
resize: (
|
|
8
|
+
w: number,
|
|
9
|
+
h: number,
|
|
10
|
+
opts: { fit: string }
|
|
11
|
+
) => {
|
|
12
|
+
stats: () => Promise<{
|
|
13
|
+
dominant?: { r: number; g: number; b: number };
|
|
14
|
+
channels?: Array<{ mean?: number }>;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
19
|
+
export async function samplePalette(
|
|
20
|
+
filePath: string
|
|
21
|
+
): Promise<Array<{ hex: string; approx_share: number }> | undefined> {
|
|
22
|
+
let sharp: SharpLike;
|
|
23
|
+
try {
|
|
24
|
+
const mod = await import('sharp');
|
|
25
|
+
const candidate = (mod as { default?: SharpLike }).default ?? (mod as unknown as SharpLike);
|
|
26
|
+
sharp = candidate;
|
|
27
|
+
} catch {
|
|
28
|
+
return undefined;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
|
|
31
|
+
try {
|
|
32
|
+
const image = sharp(filePath, { failOn: 'none' }).resize(64, 64, { fit: 'inside' });
|
|
33
|
+
const stats = await image.stats();
|
|
34
|
+
const channels = stats.channels ?? [];
|
|
35
|
+
if (stats.dominant) {
|
|
36
|
+
const { r, g, b } = stats.dominant;
|
|
37
|
+
const hex = `#${[r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('')}`;
|
|
38
|
+
return [{ hex, approx_share: 1 }];
|
|
39
|
+
}
|
|
40
|
+
if (channels.length >= 3) {
|
|
41
|
+
const r = Math.round(channels[0]?.mean ?? 0);
|
|
42
|
+
const g = Math.round(channels[1]?.mean ?? 0);
|
|
43
|
+
const b = Math.round(channels[2]?.mean ?? 0);
|
|
44
|
+
const hex = `#${[r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('')}`;
|
|
45
|
+
return [{ hex, approx_share: 1 }];
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
36
51
|
}
|
|
Binary file
|