Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

image-palette-webgpu

IvanLudvig14MIT0.1.1

A tiny zero-dependency browser package that extracts dominant color or color palette from an image using WebGPU API with various algorithms

webgpu, gpu, wgsl, shader, fast, image, photo, picture, dominant, primary, prominent, color, colors, colour, colours, palette, extract, quantize, celebi, wu, zero-dependency, zero-dependencies, tiny, es-module, esm, free, libre, open, open-source, opensource, floss, foss, oss

readme

Published on NPM

A tiny zero-dependency browser package that extracts dominant color or color palette from an image using WebGPU API with various algorithms.

Table of contents

Live demo

https://ivanludvig.dev/image-palette-webgpu/

Install

npm i image-palette-webgpu

Import

Local

JS

import { extractDominantColors } from './node_modules/image-palette-webgpu/index.js';

HTML

<script type="module">
  import { extractDominantColors } from './node_modules/image-palette-webgpu/index.js';
</script>

Import maps

<script type="importmap">
  {
    "imports": {
      "image-palette-webgpu": "./node_modules/image-palette-webgpu/index.js"
    }
  }
</script>

JS

import { extractDominantColors } from 'image-palette-webgpu';

HTML

<script type="module">
  import { extractDominantColors } from 'image-palette-webgpu';
</script>

Dev Servers / Builders

JS

import { extractDominantColors } from 'image-palette-webgpu';

HTML

<script type="module">
  import { extractDominantColors } from 'image-palette-webgpu';
</script>

CDN

UNPKG

JS

import { extractDominantColors } from 'https://unpkg.com/image-palette-webgpu';

HTML

<script type="module">
  import { extractDominantColors } from 'https://unpkg.com/image-palette-webgpu';
</script>

ESM CDN

JS

import { extractDominantColors } from 'https://esm.sh/image-palette-webgpu';

HTML

<script type="module">
  import { extractDominantColors } from 'https://esm.sh/image-palette-webgpu';
</script>

Skypack

JS

import { extractDominantColors } from 'https://cdn.skypack.dev/image-palette-webgpu';

HTML

<script type="module">
  import { extractDominantColors } from 'https://cdn.skypack.dev/image-palette-webgpu';
</script>

Use

JS

const image = new Image();
image.src = './image.png';
const colorCount = 5;
const algorithm = 'wu';
await image.decode();
const dominantColors = await extractDominantColors(image, colorCount, algorithm);
console.log(dominantColors); // ['#d65a58', '#c84c52', '#d65a59', '#bb464b', '#e3dbaa']