Open Gitii opened 10 years ago
I have experienced that MMCQ.quantize(pixelArray, colorCount); can return false, leading to a "undefined is not a function" error on palette = cmap.palette();
So it would be a good thing to add this to ensure that the page gets cleaned.
+1. Trying to use for the first time, and this is happening. Let's get this put in the code!
Hi,
the current version of ColorThief does not remove the canvas if an error has been thrown. The current versions of firefox throw an error if the passed in image has not been fully initializied (drawImage), therefore the clean up (removeCanvas) logic is never executed, a simply try ... finally takes care of this.
I rewrote/extended the logic this way: added try..finally extracted drawImage into separate function, otherwise the constructor fails and cleanup logic is never executed because image is still null.
[...] var CanvasImage = function (image) { this.canvas = document.createElement('canvas'); this.context = this.canvas.getContext('2d'); this.image = image;
};
CanvasImage.prototype.draw = function () { this.context.drawImage(this.image, 0, 0, this.width, this.height); }; [...] ColorThief.prototype.getPalette = function(sourceImage, colorCount, quality) {
}; [...]