Skip to content

Commit 7d0f483

Browse files
committed
Update display: MLH-styled sky
1 parent ead331a commit 7d0f483

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

index.html

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
max-width: 180px;
9494
max-height: 180px;
9595
display: block;
96-
mix-blend-mode: multiply;
9796
}
9897

9998
.bird-label {
@@ -132,6 +131,28 @@
132131
const kfStyle = document.getElementById('dynamic-keyframes');
133132
const countLabel = document.getElementById('bird-count');
134133

134+
function removeWhiteBackground(img) {
135+
try {
136+
const canvas = document.createElement('canvas');
137+
canvas.width = img.naturalWidth;
138+
canvas.height = img.naturalHeight;
139+
const ctx = canvas.getContext('2d');
140+
ctx.drawImage(img, 0, 0);
141+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
142+
const data = imageData.data;
143+
for (let i = 0; i < data.length; i += 4) {
144+
// If pixel is white or near-white, make it transparent
145+
if (data[i] > 235 && data[i+1] > 235 && data[i+2] > 235) {
146+
data[i+3] = 0;
147+
}
148+
}
149+
ctx.putImageData(imageData, 0, 0);
150+
img.src = canvas.toDataURL('image/png');
151+
} catch(e) {
152+
console.warn('Could not process image:', e);
153+
}
154+
}
155+
135156
async function fetchManifest() {
136157
try {
137158
const res = await fetch('manifest.json?t=' + Date.now());
@@ -172,10 +193,12 @@
172193
const timing = bird.animation.timing_function || 'ease-in-out';
173194
wrapper.style.animation = bird.animation.animation_name + ' ' + dur + ' ' + timing + ' infinite';
174195

175-
// the image
196+
// the image — remove white background via canvas on load
176197
const img = document.createElement('img');
177-
img.src = bird.image + '?raw=true';
198+
img.crossOrigin = 'anonymous';
199+
img.src = bird.image;
178200
img.className = 'bird';
201+
img.onload = function() { removeWhiteBackground(img); };
179202
wrapper.appendChild(img);
180203

181204
// name + origin label

0 commit comments

Comments
 (0)