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

Get dominant color from specific area #46

Closed
jmcbee opened this issue Oct 7, 2014 · 2 comments
Closed

Get dominant color from specific area #46

jmcbee opened this issue Oct 7, 2014 · 2 comments

Comments

@jmcbee
Copy link

jmcbee commented Oct 7, 2014

Hi, is it possible to only get the dominant color from a specific area in an image?

var canvas = document.getElementById('da-canvas');
var context = canvas.getContext('2d');
var img = new Image();
var colorThief = new ColorThief();
var bg;

img.src = 'images/thefame.jpg';
img.onload = function() {
  canvas.height = 10;
  canvas.width = this.width;
  context.drawImage(img, 0, 0, this.width, this.height);
  bg = colorThief.getColor(canvas);
  canvas.height = this.height;
  context.drawImage(img, 0, 0, this.width, this.height);
  document.getElementById('container').style.background = 'rgb(' + bg.join(',') + ')';
}

I'm trying to get only 10px from the top of the image. I thought just setting the height of the canvas will work hahaha. But it didn't.

I think this might increase the speed as well?

@jmcbee
Copy link
Author

jmcbee commented Oct 7, 2014

Here's the image I'm trying to use with this library:

Which results to rgb [38, 40, 50].

@ksubileau
Copy link

Duplicate, see #44

@jmcbee jmcbee closed this as completed Oct 7, 2014
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

2 participants