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

cp6p 9年前發布 | 14K 次閱讀 Thmclrx Node.js 開發

Thmclrx – 用于提取主題色的 Node.js 三方包 – 提取出來的主題色可以用于檢索、分類,以及將提取的色板展現給用戶看,就如 Dribbble 那樣。并且該包目前用于花瓣網中,色彩搜索的顏色就是通過該包提取。

Algorithm

  • Minimum Differ Algorithm
  • Octree Algorithm
  • </ul>

    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.baiduhome.net/lib/view/home/1436104963557

 本文由用戶 cp6p 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!