GithubHelp home page GithubHelp logo

roowme / color-thief-for-mini-program Goto Github PK

View Code? Open in Web Editor NEW

This project forked from terrywang9112/color-thief-for-mini-program

0.0 0.0 0.0 756 KB

Color Thief 小程序版本 - Color Thief For MP

License: MIT License

JavaScript 100.00%

color-thief-for-mini-program's Introduction

Color Thief For Mini Program

Color thief 小程序版本,可以用来提取图片/Canvas主色/配色 灵感和算法来自于:

使用场景:

  1. 颜色提取
  2. 向 Canvas 中添加文字前可以判断出合适的文字颜色,从而避免添加的文字不可见、不容易分辨
  3. Canvas 褪色滤镜 - 保留主色,其余颜色显示为黑白

小程序代码片段 | MP Snippet

用法 - How to use

下载、拷贝 colorThief.js 到你的项目中(正式使用前记得压缩代码或使用小程序自带的代码压缩功能),并引用它

import ColorThief from '../utils/colorThief.js'


ColorThief.getPaletteWithRaw({
  width: canvasWidth,
  height: canvasHeight,
  rawData: res.data, // Uint8ClampedArray - wx.canvasGetImageData => res.data
  colorCount: 5,
  quality: 10
}, (colors) => { // color palette

  let dominantColor = colors[0]; // dominant color(RGB)
  console.log('dominant color(RGB)', colors[0]);
});

效果

result

color-thief-for-mini-program's People

Contributors

terrywang9112 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.