# fast-average-color

> A simple library that calculates the average color of images, videos and canvas in browser environment.

Latest version **9.6.0** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-average-color
pnpm add fast-average-color
yarn add fast-average-color
bun add fast-average-color
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.6.0 |
| Published | 2026-09-11 |
| First published | 2018-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 12 |
| Dependencies | 0 |
| Unpacked size | 76.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1540 |
| Author | Denis Seleznev |
| Maintainers | hcodes |
| Keywords | fast, average, color, colour |

## Links

- npm: https://www.npmjs.com/package/fast-average-color
- Repository: https://github.com/fast-average-color/fast-average-color
- Issues: https://github.com/fast-average-color/fast-average-color/issues
- npm.io page: https://npm.io/package/fast-average-color

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 9.6.0 (latest) — 2026-09-11
- 9.5.2 — 2026-04-05
- 9.5.1 — 2026-03-30
- 9.5.0 — 2025-03-20
- 9.4.0 — 2023-08-25
- 9.3.0 — 2022-12-31
- 9.2.0 — 2022-12-18
- 9.1.1 — 2022-06-22
- 9.1.0 — 2022-06-22
- 9.0.0 — 2022-06-21
- 8.0.0 — 2022-06-20
- 7.1.0 — 2022-02-19
- 7.0.1 — 2021-10-31
- 7.0.0 — 2021-10-31
- 6.4.2 — 2021-09-04
- … 28 more at https://npm.io/package/fast-average-color/versions

## README

# 🍏🍊🍅 Fast Average Color
[![NPM version](https://img.shields.io/npm/v/fast-average-color.svg)](https://www.npmjs.com/package/fast-average-color)
[![NPM Downloads](https://img.shields.io/npm/dm/fast-average-color.svg?style=flat)](https://www.npmjs.org/package/fast-average-color)
[![install size](https://packagephobia.com/badge?p=fast-average-color)](https://packagephobia.com/result?p=fast-average-color)
![Coveralls](https://img.shields.io/coveralls/github/hcodes/fast-average-color)

[Demo](https://fast-average-color.github.io/examples/background.html)

A simple library that calculates average or dominant color of any images or videos in browser environment.
<img width="100%" style="max-width: 640px;" src="https://raw.githubusercontent.com/fast-average-color/fast-average-color/master/img/title.png" />

## Features
- Bet on [speed](https://fast-average-color.github.io/examples/canvas.html)
- Some algorithms: simple, sqrt (default) and dominant
- [Small bundle size](https://bundlephobia.com/result?p=fast-average-color), tree shaking
- Average color can be obtained from:
  + [image](https://fast-average-color.github.io/examples/background.html)
  + string (url of image or base64)
  + [video](https://fast-average-color.github.io/examples/timeline.html)
  + [canvas](https://fast-average-color.github.io/examples/canvas.html) or `OffscreenCanvas`
  + `ImageBitmap`
  + `VideoFrame`
  + array of numbers, `Uint8Array` or `Uint8ClampedArray`
- Average color can be obtained from specific part of resource
- Support for transparency (PNG, SVG and other formats)
- Support for web workers
- [Support for Node.js](https://github.com/fast-average-color/fast-average-color-node/)

## Table of contents
- [Using](./docs/using.md)
  + [Install](./docs/using.md)
  + [CommonJS](./docs/using.md#commonjs)
  + [ES Modules or TypeScript](./docs/using.md#es-modules-or-typescript)
  + [Node.js](./docs/using.md#nodejs)
- [Examples](./docs/examples.md)
  + [Get average color from loaded image](./docs/examples.md#from-loaded-image)
  + [Get average color from unloaded image](./docs/examples.md#from-unloaded-image)
  + [Get average color from image url](./docs/examples.md#from-image-url)
  + [Get average color with ignored color](./docs/examples.md#get-average-color-with-ignored-color)
  + [Get average color with multiple ignored colors](./docs/examples.md#get-average-color-with-multiple-ignored-colors)
  + [Get average color with ignored color and threshold](./docs/examples.md#get-average-color-with-ignored-color-and-threshold)
- [Algorithms](./docs/algorithms.md)
- [API](./docs/api.md)
  + [.getColor(resource, [options])](./docs/api.md#getcolorresource-options)
  + [.getColorAsync(resource, [options])](./docs/api.md#getcolorasyncresource-options)
  + [.getColorFromArray4(arr, [options])](./docs/api.md#getcolorfromarray4arr-options)
  + [.destroy()](./docs/api.md#destroy)
- [Development](./docs/development.md)

## Unhandled Rejection (SecurityError): The operation is insecure.
> The crossOrigin attribute allows images that are loaded from external origins to be used in canvas like the one they were being loaded from the current origin. Using images without CORS approval taints the canvas. Once a canvas has been tainted, you can no longer pull data back out of the canvas. By loading the canvas from cross origin domain, you are tainting the canvas.

>You can prevent this by setting crossorigin="anonymous".

- [Details](https://github.com/lokesh/color-thief/issues/196)
- [Storing an image from a foreign origin](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image#Storing_an_image_from_a_foreign_origin)


## [More examples](https://fast-average-color.github.io/examples/background.html)
  + [Background](https://fast-average-color.github.io/examples/background.html)
  + [Timeline](https://fast-average-color.github.io/examples/timeline.html)
  + [Box shadow](https://fast-average-color.github.io/examples/box-shadow.html)
  + [Box shadow, 4 sides](https://fast-average-color.github.io/examples/box-shadow-4-sides.html)
  + [Border](https://fast-average-color.github.io/examples/border.html)
  + Gallery: [borders](https://fast-average-color.github.io/examples/gallery.html) or [vertical-horizontally](https://fast-average-color.github.io/examples/gallery_vertical.html)
  + [Gradient](https://fast-average-color.github.io/examples/gradient.html)
  + [Gradient as stripes](https://fast-average-color.github.io/examples/gradient_stripes.html)
  + [Canvas](https://fast-average-color.github.io/examples/canvas.html)
  + [Text photo](https://fast-average-color.github.io/examples/text-photo.html)
  + [Ambilight](https://fast-average-color.github.io/examples/ambilight.html)
  + [Define the average color for your images](https://fast-average-color.github.io/examples/define.html)
  + [WebGL](https://fast-average-color.github.io/examples/webgl.html)
  + [Colors of movies](https://film-color.github.io/film-color/) 🎬 average color for frames

[See code](https://github.com/fast-average-color/examples)

## [License](LICENSE)
MIT License

## Similar projects
- [fast-average-color-node](https://github.com/fast-average-color/fast-average-color-node/)
- [color-thief](https://github.com/lokesh/color-thief)
- [node-vibrant](https://github.com/Vibrant-Colors/node-vibrant)
- [image-palette](https://github.com/FormidableLabs/image-palette)
- [react-color-extractor](https://github.com/nitin42/react-color-extractor)

## Friends
- [Check device online](https://checkdevice.online/?from=github-fac)

---
_Source: https://npm.io/package/fast-average-color · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
