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

Update color-thief.js #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guillaumehilaire
Copy link

for get dominant color if the file is white dominant

for get dominant color if the file is white dominant
@ksubileau
Copy link

Hi,
In fact, the script skips the white pixels (>rgb(250,250,250)) of the image in order not to return white as the dominant color of an image with a white background like below :
chats
I think that asserting that the dominant color of an image as the one above is white is not really accurate. However, if white is really part of the image (clouds in the sky, white clothes,...), it's true that it should be taken into account.
So maybe it would be better to add an option to indicate whether or not you want to ignore white pixels. Or, even better, add an option to specify one or more colors to ignore ?

@programmin1
Copy link

I see similar behavior for a mostly-dark image. Can this be behavior be turned off in an option/parameter?

@ksubileau
Copy link

No, not yet.

@alexiskattan
Copy link

it would be very nice to be able to have a flag to detect if white is the dominant color

@frumbert
Copy link

I'd like to specifically detect when white is the dominant colour of the image.

@zamartz
Copy link

zamartz commented Dec 2, 2018

@ksubileau @alexiskattan
Would it be better to:

  1. Manual = send a color list to ignore as dominant
  2. Auto = allow for ignoring the first dominant color

@@ -119,7 +119,7 @@ ColorThief.prototype.getPalette = function(sourceImage, colorCount, quality) {
a = pixels[offset + 3];
// If pixel is mostly opaque and not white
if (a >= 125) {
if (!(r > 250 && g > 250 && b > 250)) {
if (!(r > 255 && g > 255 && b > 255)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB components are never > 255 ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Thanks for the contribution. While this change adresses the issue from the OP it also breaks the intended behavior referred to earlier by @ksubileau. If you submit a PR which introduces a parameter so this can be turned off and on with appropriate defaults (ie. 'off' so people who update don't get unxepected behaviour) I'm sure someone would add appropriate tests and update the doc accordingly.

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

Successfully merging this pull request may close these issues.

None yet

8 participants