mirror of
https://github.com/janishutz/color-thief.git
synced 2025-11-25 05:44:24 +00:00
Merge pull request #150 from lokesh/dont-append-dom
refactor: Dont append canvas tag to DOM
This commit is contained in:
@@ -45,7 +45,6 @@ const showColorsForImage = function(image, section) {
|
||||
let start = Date.now();
|
||||
let result = colorThief.getPalette(image, count);
|
||||
let elapsedTime = Date.now() - start;
|
||||
console.log('palette()', count, result.length)
|
||||
paletteHTML += Mustache.to_html(document.getElementById('palette-tpl').innerHTML, {
|
||||
count,
|
||||
palette: result,
|
||||
|
||||
@@ -28,22 +28,12 @@ var CanvasImage = function (image) {
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
document.body.appendChild(this.canvas);
|
||||
|
||||
this.width = this.canvas.width = image.width;
|
||||
this.height = this.canvas.height = image.height;
|
||||
|
||||
this.context.drawImage(image, 0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.clear = function () {
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.update = function (imageData) {
|
||||
this.context.putImageData(imageData, 0, 0);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.getPixelCount = function () {
|
||||
return this.width * this.height;
|
||||
};
|
||||
@@ -52,11 +42,6 @@ CanvasImage.prototype.getImageData = function () {
|
||||
return this.context.getImageData(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.removeCanvas = function () {
|
||||
this.canvas.parentNode.removeChild(this.canvas);
|
||||
};
|
||||
|
||||
|
||||
var ColorThief = function () {};
|
||||
|
||||
/*
|
||||
@@ -132,9 +117,6 @@ ColorThief.prototype.getPalette = function(sourceImage, colorCount, quality) {
|
||||
var cmap = MMCQ.quantize(pixelArray, colorCount);
|
||||
var palette = cmap? cmap.palette() : null;
|
||||
|
||||
// Clean up
|
||||
image.removeCanvas();
|
||||
|
||||
return palette;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user