用于提取主题色的 Node.js 三方包:Thmclrx

cp6p 10年前

Thmclrx – 用于提取主题色的 Node.js 三方包 – 提取出来的主题色可以用于检索、分类,以及将提取的色板展现给用户看,就如 Dribbble 那样。并且该包目前用于花瓣网中,色彩搜索的颜色就是通过该包提取。

Algorithm

  • Minimum Differ Algorithm
  • Octree Algorithm

Installation

$ npm install thmclrx

API

There only three API in node.js now.

After version 0.2.0, we use a new memory pool for thmclrx.

octreeGet

octreeGetis to get the theme colors in an octree. The colors are unsertain but fidelity.

The function is like below:

var thmclrx = require("thmclrx");  thmclrx.octreeGet(file, [maxColors], [callback], [frameNumber]);
  • file: it could be a local filename, remote url or even an image buffer.
  • maxColors: count of max theme colors you want to extract. Defaults to 256;
  • callback: it should be likefunction(err, colors) {}. Defaults to an empty function;
  • frameNumber: the frame you want to extract. Usually used ingif. Defaults to 0.

mindiffGet

mindiffGetis to get theme colors in minimum differ algorithm by passing a palette. The result theme colors are certainlly in your palette.

var thmclrx = require("thmclrx");  thmclrx.mindiffGet(file, [palette], [callback], [frameNumber]);
  • file: it could be a local filename, remote url or even an image buffer.
  • palette: palette is an array that in the struct of[ { r: .., g: .., b: .., }, { r: .., g: .., b: .. } ]. Default palette refers here.
  • callback: it should be likefunction(err, colors) {}. Defaults to an empty function;
  • frameNumber: the frame you want to extract. Usually used ingif. Defaults to 0.

mixGet

UsingoctreeGetget the basic fidelity theme colors and then usingmindiffGetto standardize the fidelity theme colors to a certain palette.

var thmclrx = require("thmclrx");  thmclrx.mixGet(file, [firstStepMaxColors], [palette], [callback], [frameNumber]);
  • file: same as the two functions above.
  • firstStepMaxColors: same as themaxColorsinoctreeGet. Defaults to 256.
  • palette: same as thepaletteinmindiffGet. Same default value.
  • callback: same as the two functions above.
  • frameNumber: same as the two functions above.

cleanPool

Clean memory pool inthmclrxC++ program.

var thmclrx = require("thmclrx");  thmclrx.cleanPool();

Normally, you do not need to call it.

C++ API

If you want to use C++ API directly, you can refer to this.

octreeGet

This function is called inoctreeGetin node.js API.

var thmclrx = require("thmclrx/build/Release/thmclrx.node");    var colors = thmclrx.octreeGet(pixels, [maxColor]);

  • pixels: this is an array in the struct of[ { r: .., g: .., b: .., }, { r: .., g: .., b: .. } ].
  • maxColor: same as themaxColorsinoctreeGetof node.js API. Defaults to 256.
  • @return: this function will return the theme colors.

mindifferGet

This function is called inmindiffGetin node.js API.

var thmclrx = require("thmclrx/build/Release/thmclrx.node");   var colors = thmclrx.mindifferGet(pixels, [palette]);

  • pixels: this may be same as thepixelsinoctreeGetof C++ API. Otherwise, it may be the result ofoctreeGetof C++ API.
  • palette: same as thepaletteinmindiffGetof node.js API. Same default value.
  • @return: this function will return the theme colors.

cleanPool

Clean memory pool.

var thmclrx = require("thmclrx/build/Release/thmclrx.node");  thmclrx.clearPool();

Normally, you do not need to call it.

项目主页:http://www.open-open.com/lib/view/home/1436104963557