UNPKG

4.42 kBMarkdownView Raw
1# Fast Average Color
2[![NPM version](https://img.shields.io/npm/v/fast-average-color.svg)](https://www.npmjs.com/package/fast-average-color)
3[![NPM Downloads](https://img.shields.io/npm/dm/fast-average-color.svg?style=flat)](https://www.npmjs.org/package/fast-average-color)
4[![Dependency Status](https://img.shields.io/david/fast-average-color/fast-average-color.svg)](https://david-dm.org/fast-average-color/fast-average-color)
5[![bundlephobia](https://badgen.net/bundlephobia/minzip/fast-average-color)](https://bundlephobia.com/result?p=fast-average-color)
6
7A simple library that calculates the average color of any images or videos in browser environment.
8<img width="100%" style="max-width: 640px;" src="https://raw.githubusercontent.com/fast-average-color/fast-average-color/master/img/title.png" />
9
10## Features
11- Bet on speed
12- Some algorithms: simple, sqrt (default) and dominant
13- Small bundle size, tree shaking
14- Average color can be obtained from:
15 + image
16 + string (url of image)
17 + video
18 + canvas
19 + array of numbers, `Uint8Array` or `Uint8ClampedArray`
20- Average color can be obtained from specific part of resource
21- Support for transparency (PNG, SVG and other formats)
22- Support for web workers
23- [Support for Node.js](https://github.com/fast-average-color/fast-average-color-node/)
24
25## Table of contents
26- [Using](./docs/using.md)
27 + [Install](./docs/using.md)
28 + [CommonJS](./docs/using.md#commonjs)
29 + [ES Modules or TypeScript](./docs/using.md#es-modules-or-typescript)
30 + [Node.js](./docs/using.md#nodejs)
31- [Examples](./docs/examples.md)
32 + [Get average color from loaded image](./docs/examples.md#from-loaded-image)
33 + [Get average color from unloaded image](./docs/examples.md#from-unloaded-image)
34 + [Get average color from image url](./docs/examples.md#from-image-url)
35- [Algorithms](./docs/algorithms.md)
36- [API](./docs/api.md)
37 + [.getColor(resource, [options])](./docs/api.md#getcolorresource-options)
38 + [.getColorAsync(resource, [options])](./docs/api.md#getcolorasyncresource-options)
39 + [.getColorFromArray4(arr, [options])](./docs/api.md#getcolorfromarray4arr-options)
40 + [.destroy()](./docs/api.md#destroy)
41- [Different Builds](./dist/README.md)
42- [Development](./docs/development.md)
43
44## Unhandled Rejection (SecurityError): The operation is insecure.
45> 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.
46
47>You can prevent this by setting crossorigin="anonymous".
48
49- [Details](https://github.com/lokesh/color-thief/issues/196)
50- [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)
51
52
53## [More examples](https://fast-average-color.github.io/examples/background.html)
54 + [Background](https://fast-average-color.github.io/examples/background.html)
55 + [Box shadow](https://fast-average-color.github.io/examples/box-shadow.html)
56 + [Box shadow, 4 sides](https://fast-average-color.github.io/examples/box-shadow-4-sides.html)
57 + [Border](https://fast-average-color.github.io/examples/border.html)
58 + [Gallery](https://fast-average-color.github.io/examples/gallery.html)
59 + [Gradient](https://fast-average-color.github.io/examples/gradient.html)
60 + [Gradient as stripes](https://fast-average-color.github.io/examples/gradient_stripes.html)
61 + [Canvas](https://fast-average-color.github.io/examples/canvas.html)
62 + [Text photo](https://fast-average-color.github.io/examples/text-photo.html)
63 + [Ambilight](https://fast-average-color.github.io/examples/ambilight.html)
64 + [Define the average color for your images](https://fast-average-color.github.io/examples/define.html)
65
66[See code](https://github.com/fast-average-color/examples)
67
68## [License](LICENSE)
69MIT License
70
71## Links
72- [fast-average-color-node](https://github.com/fast-average-color/fast-average-color-node/)
73- [color-thief](https://github.com/lokesh/color-thief)
74- [node-vibrant](https://github.com/Vibrant-Colors/node-vibrant)
75- [image-palette](https://github.com/FormidableLabs/image-palette)
76- [react-color-extractor](https://github.com/nitin42/react-color-extractor)