Skip to content

Commit a05199e

Browse files
committed
fix
1 parent 9c2a46c commit a05199e

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{% include v1/footer.html %}
3838
</footer>
3939
{% if page.url == '/' or page.url == '/index.html' %}
40-
<script src="{{ '/assets/js/ascii-bg.js' | relative_url }}?v=ascii-mobile-dark-20260329-4"></script>
40+
<script src="{{ '/assets/js/ascii-bg.js' | relative_url }}?v=ascii-mobile-inkmask-20260329-5"></script>
4141
{% endif %}
4242
<script src="{{ '/assets/js/terminal-tilt.js' | relative_url }}"></script>
4343
</body>

assets/js/ascii-bg.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,41 @@
1414
w: 0,
1515
h: 0,
1616
loaded: false,
17+
maskCanvas: null,
18+
};
19+
20+
const buildInkMask = () => {
21+
const w = img.naturalWidth || img.width || 0;
22+
const h = img.naturalHeight || img.height || 0;
23+
if (!w || !h) return null;
24+
25+
const off = document.createElement("canvas");
26+
off.width = w;
27+
off.height = h;
28+
const octx = off.getContext("2d");
29+
if (!octx) return null;
30+
octx.drawImage(img, 0, 0, w, h);
31+
32+
const imageData = octx.getImageData(0, 0, w, h);
33+
const data = imageData.data;
34+
for (let i = 0; i < data.length; i += 4) {
35+
const r = data[i];
36+
const g = data[i + 1];
37+
const b = data[i + 2];
38+
const lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
39+
const ink = 255 - lum;
40+
if (ink < 22) {
41+
data[i + 3] = 0;
42+
continue;
43+
}
44+
const alpha = Math.min(255, (ink - 22) * 1.6);
45+
data[i] = 210;
46+
data[i + 1] = 210;
47+
data[i + 2] = 214;
48+
data[i + 3] = alpha;
49+
}
50+
octx.putImageData(imageData, 0, 0);
51+
return off;
1752
};
1853

1954
const draw = () => {
@@ -27,26 +62,26 @@
2762
if (!state.loaded) return;
2863

2964
// Cover fit to fill viewport.
30-
const iw = img.naturalWidth || 1;
31-
const ih = img.naturalHeight || 1;
65+
const source = state.maskCanvas || img;
66+
const iw = source.width || img.naturalWidth || 1;
67+
const ih = source.height || img.naturalHeight || 1;
3268
const scale = Math.max(state.w / iw, state.h / ih);
3369
const dw = iw * scale;
3470
const dh = ih * scale;
3571
const dx = (state.w - dw) * 0.5;
3672
const dy = (state.h - dh) * 0.5;
3773
const mobile = Math.max(0, Math.min(1, state.w / 900));
3874

39-
// Near-black but visible, with stronger darkening on mobile.
40-
const brightness = 0.14 + mobile * 0.06; // ~0.166 on iPhone widths, ~0.20 desktop
41-
const baseAlpha = 0.62 + mobile * 0.28; // reduce image weight on smaller screens
42-
ctx.filter = `grayscale(1) contrast(1.05) brightness(${brightness.toFixed(3)})`;
75+
// Draw extracted ASCII ink only (white background removed), darker on mobile.
76+
const baseAlpha = 0.24 + mobile * 0.26;
77+
ctx.filter = "none";
4378
ctx.globalAlpha = baseAlpha;
44-
ctx.drawImage(img, dx, dy, dw, dh);
79+
ctx.drawImage(source, dx, dy, dw, dh);
4580

4681
// Slight dark veil so foreground content stays readable.
4782
ctx.filter = "none";
4883
ctx.globalAlpha = 1;
49-
const veil = 0.62 - mobile * 0.20; // stronger veil on mobile
84+
const veil = 0.70 - mobile * 0.22; // stronger veil on mobile
5085
ctx.fillStyle = `rgba(0, 0, 0, ${veil.toFixed(3)})`;
5186
ctx.fillRect(0, 0, state.w, state.h);
5287

@@ -81,6 +116,7 @@
81116
};
82117

83118
img.onload = () => {
119+
state.maskCanvas = buildInkMask();
84120
state.loaded = true;
85121
draw();
86122
};

0 commit comments

Comments
 (0)