1.0.11 • Published 2 years ago

color-thief-wasm-miniprogram v1.0.11

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

WebAssembly for Color Thief algorithm

Use WASM implement Color Thief algorithm for high performance

ref: color-thief

Install

You can install specify dependcines for different platform.

Node.js

$ npm i color-thief-wasm

Web

$ npm i color-thief-wasm-web

Bundler(Webpack)

$ npm i color-thief-wasm-bundler

miniprogram

$ npm i color-thief-wasm-miniprogram

How to use

In Node.js

const {
    get_color_thief
} = require('color-thief-wasm')
// export function get_color_thief(colors: Uint8Array, pixel_count: number, quality: number, colors_count: number): Array<any>;
const colors = get_color_thief(data, 64 * 64, 10, 5)

In web

<script type="module">
    import init,{
        get_color_thief
    } from "./pkg-web/color_thief_wasm.js"
    init().then(() => {
      const colors = get_color_thief(data, 64 * 64, 10, 5)
      console.log(colors)
    })
</script>

In miniprogram,we must modify wasm-pack build output content for compatable

ref: wasm-pack + miniprogram

import init, { get_color_thief } from 'color-thief-wasm-miniprogram/color_thief_wasm'
await init('/xxxpath/color_thief_wasm_bg.wasm') // there must provide absolute path in miniprogram
const colors = get_color_thief(data, 64 * 64, 10, 5)

Or you can copy color-thief-wasm-miniprogram to your project for convenience that you can

$ tree ./ -I node_modules -L 2
./
├── miniprogram
│   ├── app.json
│   ├── app.less
│   ├── app.ts
│   ├── pages
│   ├── color-thief-wasm-miniprogram
│   └── utils
├── package-lock.json
├── package.json
├── project.config.json
├── tsconfig.json
├── typings
│   ├── index.d.ts
│   └── types
// pages/index/index.js
import init, { get_color_thief } from '../../color-thief-wasm-miniprogram/color_thief_wasm'
await init('/color-thief-wasm-miniprogram/color_thief_wasm_bg.wasm') // there must provide absolute path
const colors = get_color_thief(data, 64 * 64, 10, 5)

How to build

Before Build, must install rust wasm-pack and pnpm

$ npm run build

benchmark

$ npm run bench
> color-thief-wasm@1.0.2 bench
> node bench.js

Running "GetColorThief" suite...
Progress: 100%

  Wasm GetColorThief:
    12 983 ops/s, ±3.27%   | fastest

  JavaScript GetColorThief:
    2 021 ops/s, ±6.99%    | slowest, 84.43% slower

Finished 2 cases!
  Fastest: Wasm GetColorThief
  Slowest: JavaScript GetColorThief

Publish

$ npm version patch && git push origin master
1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago