asciify-engine 1.0.46 → 1.0.48
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 -10
- package/dist/index.cjs +19 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,8 +129,8 @@ All conversion and render functions accept an `AsciiOptions` object. Spread `DEF
|
|
|
129
129
|
| `invert` | `boolean` | `false` | Inverts the luminance mapping — light areas become dense, dark areas sparse. |
|
|
130
130
|
| `renderMode` | `'ascii' \| 'dots'` | `'ascii'` | Render as text characters or circular dot particles. |
|
|
131
131
|
| `hoverEffect` | `string` | `'none'` | Interactive effect driven by cursor position. See hover effects below. |
|
|
132
|
-
| `hoverStrength` | `number` | `0
|
|
133
|
-
| `hoverRadius` | `number` | `0.
|
|
132
|
+
| `hoverStrength` | `number` | `0` | Effect intensity (0–1). `0` = hover disabled. |
|
|
133
|
+
| `hoverRadius` | `number` | `0.2` | Effect radius relative to canvas size (0–1). |
|
|
134
134
|
| `chromaKey` | `{r,g,b} \| string \| null` | `null` | Remove a background colour (green/blue screen). Keyed pixels become transparent spaces. Accepts `{r,g,b}`, any CSS colour string, or `null` to disable. |
|
|
135
135
|
| `chromaKeyTolerance` | `number` | `60` | Euclidean RGB distance threshold for chroma-key detection. `0` = exact match, higher = more pixels removed (max useful ~100). |
|
|
136
136
|
|
|
@@ -141,14 +141,9 @@ Remove a solid background colour from any source — images, GIFs, or video —
|
|
|
141
141
|
```ts
|
|
142
142
|
import { asciify, DEFAULT_OPTIONS } from 'asciify-engine';
|
|
143
143
|
|
|
144
|
-
// Green screen
|
|
144
|
+
// Green screen — zero config, just set true:
|
|
145
145
|
asciify(img, canvas, {
|
|
146
|
-
options: {
|
|
147
|
-
...DEFAULT_OPTIONS,
|
|
148
|
-
chromaKey: '#00ff00', // CSS colour string — hex, rgb(), named all work
|
|
149
|
-
chromaKeyTolerance: 60, // tune to your footage (0 = exact, ~80 = loose)
|
|
150
|
-
colorMode: 'fullcolor',
|
|
151
|
-
},
|
|
146
|
+
options: { ...DEFAULT_OPTIONS, chromaKey: true, colorMode: 'fullcolor' },
|
|
152
147
|
});
|
|
153
148
|
|
|
154
149
|
// Blue screen
|
|
@@ -164,7 +159,7 @@ asciify(img, canvas, {
|
|
|
164
159
|
// Live video with green screen
|
|
165
160
|
asciifyVideo('/footage.mp4', canvas, {
|
|
166
161
|
fitTo: '#container',
|
|
167
|
-
options: { ...DEFAULT_OPTIONS, chromaKey:
|
|
162
|
+
options: { ...DEFAULT_OPTIONS, chromaKey: true, colorMode: 'fullcolor' },
|
|
168
163
|
});
|
|
169
164
|
```
|
|
170
165
|
|
package/dist/index.cjs
CHANGED
|
@@ -648,10 +648,14 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
648
648
|
normRange = hi > lo ? hi - lo : 255;
|
|
649
649
|
}
|
|
650
650
|
const frame = [];
|
|
651
|
+
const ck = options.chromaKey;
|
|
652
|
+
const ckEnabled = ck != null && ck !== false;
|
|
653
|
+
const ckHeuristicGreen = ck === true;
|
|
654
|
+
const ckHeuristicBlue = ck === "blue-screen";
|
|
651
655
|
let ckRGB = null;
|
|
652
656
|
let ckTolSq = 0;
|
|
653
|
-
if (
|
|
654
|
-
ckRGB = parseChromaKeyColor(
|
|
657
|
+
if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
|
|
658
|
+
ckRGB = parseChromaKeyColor(ck);
|
|
655
659
|
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
656
660
|
}
|
|
657
661
|
for (let y = 0; y < rows; y++) {
|
|
@@ -662,11 +666,19 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
662
666
|
const g = pixels[i + 1];
|
|
663
667
|
const b = pixels[i + 2];
|
|
664
668
|
const a = pixels[i + 3];
|
|
665
|
-
if (
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
if (
|
|
669
|
+
if (ckEnabled) {
|
|
670
|
+
let keyed = false;
|
|
671
|
+
if (ckHeuristicGreen) {
|
|
672
|
+
keyed = g > r * 1.4 && g > b * 1.4 && g > 80;
|
|
673
|
+
} else if (ckHeuristicBlue) {
|
|
674
|
+
keyed = b > r * 1.4 && b > g * 1.4 && b > 80;
|
|
675
|
+
} else if (ckRGB !== null) {
|
|
676
|
+
const dr = r - ckRGB.r;
|
|
677
|
+
const dg = g - ckRGB.g;
|
|
678
|
+
const db = b - ckRGB.b;
|
|
679
|
+
keyed = dr * dr + dg * dg + db * db <= ckTolSq;
|
|
680
|
+
}
|
|
681
|
+
if (keyed) {
|
|
670
682
|
row.push({ char: " ", r: 0, g: 0, b: 0, a: 0 });
|
|
671
683
|
continue;
|
|
672
684
|
}
|