|
93 | 93 | max-width: 180px; |
94 | 94 | max-height: 180px; |
95 | 95 | display: block; |
96 | | - mix-blend-mode: multiply; |
97 | 96 | } |
98 | 97 |
|
99 | 98 | .bird-label { |
|
132 | 131 | const kfStyle = document.getElementById('dynamic-keyframes'); |
133 | 132 | const countLabel = document.getElementById('bird-count'); |
134 | 133 |
|
| 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 | + |
135 | 156 | async function fetchManifest() { |
136 | 157 | try { |
137 | 158 | const res = await fetch('manifest.json?t=' + Date.now()); |
|
172 | 193 | const timing = bird.animation.timing_function || 'ease-in-out'; |
173 | 194 | wrapper.style.animation = bird.animation.animation_name + ' ' + dur + ' ' + timing + ' infinite'; |
174 | 195 |
|
175 | | - // the image |
| 196 | + // the image — remove white background via canvas on load |
176 | 197 | const img = document.createElement('img'); |
177 | | - img.src = bird.image + '?raw=true'; |
| 198 | + img.crossOrigin = 'anonymous'; |
| 199 | + img.src = bird.image; |
178 | 200 | img.className = 'bird'; |
| 201 | + img.onload = function() { removeWhiteBackground(img); }; |
179 | 202 | wrapper.appendChild(img); |
180 | 203 |
|
181 | 204 | // name + origin label |
|
0 commit comments