setTimeout(function() { var size = 40; var id = context.getImageData(0, 0, width, height); var white = getPixelColor(id, width, height, 0, height-1); for(var x = 0; x < width; x++) { for(var y = 0; y < height; y++) { var index = (x + y * id.width) * 4; id.data[index+0] = (white.r ? 255/white.r : 1) * id.data[index+0]; id.data[index+1] = (white.g ? 255/white.g : 1) * id.data[index+1]; id.data[index+2] = (white.b ? 255/white.b : 1) * id.data[index+2]; var t = 220; if (id.data[index+0] > t && id.data[index+1] > t && id.data[index+2] > t) { id.data[index+0] = 0; id.data[index+1] = 255; id.data[index+2] = 0; id.data[index+3] = 0; var size = 5; for(var w = -Math.floor(size/2); w <= Math.floor(size/2); w++) { for(var z = -Math.floor(size/2); z <= Math.floor(size/2); z++) { if ((x + w) < width || (y + z) < height) { var i = ((x + w) + (y + z) * id.width) * 4; id.data[i+0] = 0; id.data[i+1] = 255; id.data[i+2] = 0; id.data[i+3] = 0; } } } } } } context.putImageData(id, 0, 0); var colors = palette(canvas, 2); canvas.toBuffer(function(err, buf){ fs.writeFile(__dirname + croppedPath, buf, function() { callback(null, { path: croppedPath, sourcePath: imagePath, colors: colors }); }); }); }, 10);
fs.readFile(path, function(err, buf){ if (err) return fn(err); var canvas = new Canvas , ctx = canvas.getContext('2d') , img = new Image; img.src = buf; canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); var colors = palette(canvas, n).map(rgb); fn(null, colors); });
img.onload = function(){ canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); var colors = palette(canvas, (parseInt((req.query.colorCount || config.colorCount), 10))), length = colors.length, i = 0, theHex = '', theName = ''; response.colors = []; colors.forEach(function(color){ theHex = '#' + (color[0] << 16 | color[1] << 8 | color[2]).toString(16); theName = ntc.name(theHex); response.colors.push({ r: color[0], g: color[1], b: color[2], hex: theHex, name: theName[1] }); i++; if (i == length) { finish(); } }); };