IMP: try to avoid black/white colors extracted from cover

This commit is contained in:
Julien Maille 2021-11-16 18:45:47 +01:00
parent dfc2c79921
commit b610a0dd8b

View file

@ -696,12 +696,20 @@ async function pickCoverColor(img) {
$("html").css("--image-brightness", getImageLightness(img) / 255); $("html").css("--image-brightness", getImageLightness(img) / 255);
sidebarColor = "#509bf5";
if (img.complete) { if (img.complete) {
sidebarColor = chroma(colorThief.getColor(img)).hex(); const dominant = colorThief.getColor(img);
} else { let palette = colorThief.getPalette(img);
sidebarColor = "#509bf5"; palette.unshift(dominant);
sidebarColor = chroma(dominant).hex();
for (const col of palette) {
const chrmCol = chroma(col);
if (chrmCol.luminance() > 0.05 && chrmCol.luminance() < 0.9) {
sidebarColor = chrmCol.hex();
break;
}
}
} }
updateColors(sidebarColor); updateColors(sidebarColor);
} }