Follow

配色好难处理啊,MDC的primaryColor和secondaryColor到底是怎么调出来的?目前只能做到这个水平了 :milkbear_035:

const image = new Image();
image.crossOrigin = "anonymous";
image.src = this.$props.song.thumbnail;
image.addEventListener("load", async (event) => {
  const colorThief = new ColorThief();
  let color = await colorThief.getColor(image);
  const contrast = chroma.contrast(chroma(...color).hex(), "#ffffff");
  if (contrast < 4) return;
  this.primaryColor = chroma(...color).hex();
  this.secondaryColor = chroma(...color)
    .brighten()
    .hex();
  this.darkColor = chroma(...color)
    .darken()
    .hex();
  this.lightColor = chroma(...color)
    .brighten(2.5)
    .hex();
});

vis4.net/chromajs

· · Web · 2 · 1 · 5

@mashiro :aru_0560: 需求是提取突出的颜色?ColorThief好像没有node-vibrant好用

Sign in to participate in the conversation
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。