avatarsniff 0.1.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.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/chunk-B5TUEKW2.cjs +20 -0
- package/dist/chunk-ESH45ZBG.cjs +10 -0
- package/dist/chunk-PFMIBRDS.js +7 -0
- package/dist/chunk-PNNWYQXN.js +17 -0
- package/dist/index.cjs +834 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +824 -0
- package/dist/jpeg-js-6X443IYI.js +2141 -0
- package/dist/jpeg-js-H7NYMOHI.cjs +2143 -0
- package/dist/svg.cjs +611 -0
- package/dist/svg.d.cts +5 -0
- package/dist/svg.d.ts +5 -0
- package/dist/svg.js +609 -0
- package/dist/types-BlZG8aqK.d.cts +98 -0
- package/dist/types-BlZG8aqK.d.ts +98 -0
- package/dist/webp.cjs +1385 -0
- package/dist/webp.d.cts +5 -0
- package/dist/webp.d.ts +5 -0
- package/dist/webp.js +1382 -0
- package/package.json +98 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Raw image pixels to analyse. Accepts 3-channel (RGB) or 4-channel (RGBA)
|
|
2
|
+
* data - alpha is flattened over white. Works with anything that can produce a
|
|
3
|
+
* pixel buffer: `sharp().raw()`, a `<canvas>` `ImageData`, `node-canvas`, etc. */
|
|
4
|
+
interface RgbaImage {
|
|
5
|
+
data: Uint8Array | Uint8ClampedArray | number[];
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
/** 3 (RGB) or 4 (RGBA). Inferred from `data.length` when omitted. */
|
|
9
|
+
channels?: number;
|
|
10
|
+
}
|
|
11
|
+
type ImageFormat = "png" | "jpeg" | "gif" | "webp" | "svg" | "unknown";
|
|
12
|
+
/**
|
|
13
|
+
* The families of default avatar the detector recognises. Each is an
|
|
14
|
+
* independent structural detector; a verdict reports which one (if any) fired:
|
|
15
|
+
* - `initials` - a near-white initial drawn on a flat saturated colour;
|
|
16
|
+
* - `solidColor` - a flat saturated colour block with no glyph;
|
|
17
|
+
* - `personIcon` - a grey/desaturated person silhouette on a light background;
|
|
18
|
+
* - `identicon` - a mirror-symmetric blocky pattern (GitHub/Gravatar style).
|
|
19
|
+
*/
|
|
20
|
+
type DetectorName = "initials" | "solidColor" | "personIcon" | "identicon";
|
|
21
|
+
declare const DETECTOR_NAMES: readonly DetectorName[];
|
|
22
|
+
/** Per-family on/off switches. Every family defaults to `true`; set one to
|
|
23
|
+
* `false` to opt out of that detector. */
|
|
24
|
+
type DetectorToggles = Partial<Record<DetectorName, boolean>>;
|
|
25
|
+
interface DecodeOptions {
|
|
26
|
+
/** Reject inputs larger than this many bytes before decoding (default 10MB). */
|
|
27
|
+
maxBytes?: number;
|
|
28
|
+
}
|
|
29
|
+
interface DetectOptions extends DecodeOptions {
|
|
30
|
+
/** Which detector families to run. Each defaults to `true`; set a family to
|
|
31
|
+
* `false` to skip it (e.g. `{ detect: { identicon: false } }`). */
|
|
32
|
+
detect?: DetectorToggles;
|
|
33
|
+
/** Edge length the image is downsampled to before sampling (default 48). */
|
|
34
|
+
sampleSize?: number;
|
|
35
|
+
/** Bits dropped per channel when quantising colours (default 4 => 16 levels). */
|
|
36
|
+
quantizeBits?: number;
|
|
37
|
+
/** Min fraction a colour must cover to count as "significant" (default 0.02). */
|
|
38
|
+
noiseFloor?: number;
|
|
39
|
+
/** Background must cover at least this fraction of the frame (default 0.55). */
|
|
40
|
+
minDominantFraction?: number;
|
|
41
|
+
/** Max significant colours allowed for a default (default 4). */
|
|
42
|
+
maxSignificantColors?: number;
|
|
43
|
+
/** Verdict score threshold in [0,1] (default 0.6). */
|
|
44
|
+
scoreThreshold?: number;
|
|
45
|
+
/** Per-channel value at/above which the dominant background is "white"
|
|
46
|
+
* (default 224). A near-white background is a logo/photo on white. */
|
|
47
|
+
whiteCutoff?: number;
|
|
48
|
+
/** Per-channel value at/below which the dominant background is "black"
|
|
49
|
+
* (default 40). Provider defaults never use near-black backgrounds. */
|
|
50
|
+
blackCutoff?: number;
|
|
51
|
+
/** Per-channel value at/above which a pixel is part of the white glyph
|
|
52
|
+
* (default 200). */
|
|
53
|
+
glyphWhiteCutoff?: number;
|
|
54
|
+
/** Min fraction of near-white pixels for the image to have a glyph
|
|
55
|
+
* (default 0.008). Solid blocks have ~none; even thin letters clear this. */
|
|
56
|
+
minGlyphFraction?: number;
|
|
57
|
+
/** Max fraction of "coloured content" (neither background nor glyph) a
|
|
58
|
+
* default may have (default 0.06). Photos/illustrations have lots. */
|
|
59
|
+
maxColoredContent?: number;
|
|
60
|
+
/** `solidColor`: min dominant fraction for a flat colour block (default 0.92). */
|
|
61
|
+
solidMinDominantFraction?: number;
|
|
62
|
+
/** `personIcon`/`identicon`: min vertical mirror-symmetry in [0,1] a generated
|
|
63
|
+
* pattern must reach (default 0.9). Real photos sit well below this. */
|
|
64
|
+
minSymmetry?: number;
|
|
65
|
+
/** `personIcon`: max mean per-pixel chroma (max-min channel) for the image to
|
|
66
|
+
* count as greyscale (default 18). */
|
|
67
|
+
maxGrayChroma?: number;
|
|
68
|
+
/** `personIcon`: min fraction of near-white pixels forming the figure
|
|
69
|
+
* (default 0.1). */
|
|
70
|
+
minPersonFigureFraction?: number;
|
|
71
|
+
/** `identicon`: min symmetry for the pattern (default 0.92, slightly stricter
|
|
72
|
+
* than `minSymmetry`). */
|
|
73
|
+
identiconMinSymmetry?: number;
|
|
74
|
+
/** `identicon`: min foreground fraction (non-dominant pixels) (default 0.12). */
|
|
75
|
+
identiconMinForeground?: number;
|
|
76
|
+
/** `identicon`: max significant colours allowed (default 6). */
|
|
77
|
+
identiconMaxColors?: number;
|
|
78
|
+
}
|
|
79
|
+
interface DefaultAvatarDetection {
|
|
80
|
+
/** Confident verdict: true => looks like a generic/default provider avatar. */
|
|
81
|
+
isDefault: boolean;
|
|
82
|
+
/** Which detector family matched, or `null` when nothing did. */
|
|
83
|
+
matched: DetectorName | null;
|
|
84
|
+
/** Score in [0,1]; higher = more default-like. For logging/tuning. */
|
|
85
|
+
score: number;
|
|
86
|
+
/** Fraction of pixels belonging to the single most common quantised colour. */
|
|
87
|
+
dominantFraction: number;
|
|
88
|
+
/** Count of distinct quantised colours each covering >= the noise floor. */
|
|
89
|
+
significantColors: number;
|
|
90
|
+
/** Fraction of near-white pixels - the glyph (initial) on a real default. */
|
|
91
|
+
glyphFraction: number;
|
|
92
|
+
/** Fraction of pixels that are neither background nor glyph - actual content. */
|
|
93
|
+
coloredOtherFraction: number;
|
|
94
|
+
/** Short human-readable reason for the verdict. */
|
|
95
|
+
reason: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type DetectOptions as D, type ImageFormat as I, type RgbaImage as R, type DefaultAvatarDetection as a, type DecodeOptions as b, DETECTOR_NAMES as c, type DetectorName as d, type DetectorToggles as e };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Raw image pixels to analyse. Accepts 3-channel (RGB) or 4-channel (RGBA)
|
|
2
|
+
* data - alpha is flattened over white. Works with anything that can produce a
|
|
3
|
+
* pixel buffer: `sharp().raw()`, a `<canvas>` `ImageData`, `node-canvas`, etc. */
|
|
4
|
+
interface RgbaImage {
|
|
5
|
+
data: Uint8Array | Uint8ClampedArray | number[];
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
/** 3 (RGB) or 4 (RGBA). Inferred from `data.length` when omitted. */
|
|
9
|
+
channels?: number;
|
|
10
|
+
}
|
|
11
|
+
type ImageFormat = "png" | "jpeg" | "gif" | "webp" | "svg" | "unknown";
|
|
12
|
+
/**
|
|
13
|
+
* The families of default avatar the detector recognises. Each is an
|
|
14
|
+
* independent structural detector; a verdict reports which one (if any) fired:
|
|
15
|
+
* - `initials` - a near-white initial drawn on a flat saturated colour;
|
|
16
|
+
* - `solidColor` - a flat saturated colour block with no glyph;
|
|
17
|
+
* - `personIcon` - a grey/desaturated person silhouette on a light background;
|
|
18
|
+
* - `identicon` - a mirror-symmetric blocky pattern (GitHub/Gravatar style).
|
|
19
|
+
*/
|
|
20
|
+
type DetectorName = "initials" | "solidColor" | "personIcon" | "identicon";
|
|
21
|
+
declare const DETECTOR_NAMES: readonly DetectorName[];
|
|
22
|
+
/** Per-family on/off switches. Every family defaults to `true`; set one to
|
|
23
|
+
* `false` to opt out of that detector. */
|
|
24
|
+
type DetectorToggles = Partial<Record<DetectorName, boolean>>;
|
|
25
|
+
interface DecodeOptions {
|
|
26
|
+
/** Reject inputs larger than this many bytes before decoding (default 10MB). */
|
|
27
|
+
maxBytes?: number;
|
|
28
|
+
}
|
|
29
|
+
interface DetectOptions extends DecodeOptions {
|
|
30
|
+
/** Which detector families to run. Each defaults to `true`; set a family to
|
|
31
|
+
* `false` to skip it (e.g. `{ detect: { identicon: false } }`). */
|
|
32
|
+
detect?: DetectorToggles;
|
|
33
|
+
/** Edge length the image is downsampled to before sampling (default 48). */
|
|
34
|
+
sampleSize?: number;
|
|
35
|
+
/** Bits dropped per channel when quantising colours (default 4 => 16 levels). */
|
|
36
|
+
quantizeBits?: number;
|
|
37
|
+
/** Min fraction a colour must cover to count as "significant" (default 0.02). */
|
|
38
|
+
noiseFloor?: number;
|
|
39
|
+
/** Background must cover at least this fraction of the frame (default 0.55). */
|
|
40
|
+
minDominantFraction?: number;
|
|
41
|
+
/** Max significant colours allowed for a default (default 4). */
|
|
42
|
+
maxSignificantColors?: number;
|
|
43
|
+
/** Verdict score threshold in [0,1] (default 0.6). */
|
|
44
|
+
scoreThreshold?: number;
|
|
45
|
+
/** Per-channel value at/above which the dominant background is "white"
|
|
46
|
+
* (default 224). A near-white background is a logo/photo on white. */
|
|
47
|
+
whiteCutoff?: number;
|
|
48
|
+
/** Per-channel value at/below which the dominant background is "black"
|
|
49
|
+
* (default 40). Provider defaults never use near-black backgrounds. */
|
|
50
|
+
blackCutoff?: number;
|
|
51
|
+
/** Per-channel value at/above which a pixel is part of the white glyph
|
|
52
|
+
* (default 200). */
|
|
53
|
+
glyphWhiteCutoff?: number;
|
|
54
|
+
/** Min fraction of near-white pixels for the image to have a glyph
|
|
55
|
+
* (default 0.008). Solid blocks have ~none; even thin letters clear this. */
|
|
56
|
+
minGlyphFraction?: number;
|
|
57
|
+
/** Max fraction of "coloured content" (neither background nor glyph) a
|
|
58
|
+
* default may have (default 0.06). Photos/illustrations have lots. */
|
|
59
|
+
maxColoredContent?: number;
|
|
60
|
+
/** `solidColor`: min dominant fraction for a flat colour block (default 0.92). */
|
|
61
|
+
solidMinDominantFraction?: number;
|
|
62
|
+
/** `personIcon`/`identicon`: min vertical mirror-symmetry in [0,1] a generated
|
|
63
|
+
* pattern must reach (default 0.9). Real photos sit well below this. */
|
|
64
|
+
minSymmetry?: number;
|
|
65
|
+
/** `personIcon`: max mean per-pixel chroma (max-min channel) for the image to
|
|
66
|
+
* count as greyscale (default 18). */
|
|
67
|
+
maxGrayChroma?: number;
|
|
68
|
+
/** `personIcon`: min fraction of near-white pixels forming the figure
|
|
69
|
+
* (default 0.1). */
|
|
70
|
+
minPersonFigureFraction?: number;
|
|
71
|
+
/** `identicon`: min symmetry for the pattern (default 0.92, slightly stricter
|
|
72
|
+
* than `minSymmetry`). */
|
|
73
|
+
identiconMinSymmetry?: number;
|
|
74
|
+
/** `identicon`: min foreground fraction (non-dominant pixels) (default 0.12). */
|
|
75
|
+
identiconMinForeground?: number;
|
|
76
|
+
/** `identicon`: max significant colours allowed (default 6). */
|
|
77
|
+
identiconMaxColors?: number;
|
|
78
|
+
}
|
|
79
|
+
interface DefaultAvatarDetection {
|
|
80
|
+
/** Confident verdict: true => looks like a generic/default provider avatar. */
|
|
81
|
+
isDefault: boolean;
|
|
82
|
+
/** Which detector family matched, or `null` when nothing did. */
|
|
83
|
+
matched: DetectorName | null;
|
|
84
|
+
/** Score in [0,1]; higher = more default-like. For logging/tuning. */
|
|
85
|
+
score: number;
|
|
86
|
+
/** Fraction of pixels belonging to the single most common quantised colour. */
|
|
87
|
+
dominantFraction: number;
|
|
88
|
+
/** Count of distinct quantised colours each covering >= the noise floor. */
|
|
89
|
+
significantColors: number;
|
|
90
|
+
/** Fraction of near-white pixels - the glyph (initial) on a real default. */
|
|
91
|
+
glyphFraction: number;
|
|
92
|
+
/** Fraction of pixels that are neither background nor glyph - actual content. */
|
|
93
|
+
coloredOtherFraction: number;
|
|
94
|
+
/** Short human-readable reason for the verdict. */
|
|
95
|
+
reason: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type DetectOptions as D, type ImageFormat as I, type RgbaImage as R, type DefaultAvatarDetection as a, type DecodeOptions as b, DETECTOR_NAMES as c, type DetectorName as d, type DetectorToggles as e };
|