MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / detectBackgroundColor

Function detectBackgroundColor

web/js/main.js:424–430  ·  view source on GitHub ↗
(imageData)

Source from the content-addressed store, hash-verified

422}
423
424function detectBackgroundColor(imageData) {
425 const d = imageData.data;
426 const corners = [0, (imageData.width-1)*4, (imageData.height-1)*imageData.width*4, d.length-4];
427 let r=0, g=0, b=0, a=0;
428 corners.forEach(i => { r+=d[i]; g+=d[i+1]; b+=d[i+2]; a+=d[i+3]; });
429 return [Math.round(r/4), Math.round(g/4), Math.round(b/4), Math.round(a/4)];
430}
431
432function removeAntiAliasing(imageData, bg, threshold = 30) {
433 const d = imageData.data;

Callers 1

processImageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected