Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if a image just have a color, "getPalette" methods is throw error #242

Open
AursorDev opened this issue Jun 19, 2023 · 3 comments
Open

if a image just have a color, "getPalette" methods is throw error #242

AursorDev opened this issue Jun 19, 2023 · 3 comments

Comments

@AursorDev
Copy link

AursorDev commented Jun 19, 2023

Hello
When I use it to get color,i upload this image,but it is throw error
white image

and the code is:

app.post("/colors", upload.single("file"), async (req, res) => {
  const fileExt =
    req.file.originalname.split(".")[
      req.file.originalname.split(".").length - 1
    ];
  try {
    fs.renameSync(
      path.resolve(__dirname, req.file.path),
      `${req.file.path}.${fileExt}`
    );

    const color = await ColorThief.getPalette(
      path.resolve(__dirname, `${req.file.path}.${fileExt}`),
      2,
      500
    );

    res.status(200).send(color);
  } catch (e) {
    console.log("e:", e);
    res.status(500).send("图片处理失败!");
  }
});
@john-doherty
Copy link

Why was this closed without a solution/fix?

@drzoidberg33
Copy link

I ran into this yesterday too.

It's because color-thief will fail on any image that only has white/near-white pixels:

color-thief/src/core.js

Lines 12 to 17 in 4dc3bb0

// If pixel is mostly opaque and not white
if (typeof a === 'undefined' || a >= 125) {
if (!(r > 250 && g > 250 && b > 250)) {
pixelArray.push([r, g, b]);
}
}

@AursorDev
Copy link
Author

AursorDev commented Apr 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants