### Node.js Installation and Usage Source: https://lokeshdhakar.com/projects/color-thief Install sharp as a dependency and use the library in a Node.js environment. ```bash npm install sharp ``` ```javascript import { getColor, getPalette } from 'colorthief'; const color = await getColor('photo.jpg'); console.log(color.hex()); const palette = await getPalette('photo.jpg', { colorCount: 5 }); palette.forEach(c => console.log(c.hex())); ``` -------------------------------- ### Install Color Thief Source: https://lokeshdhakar.com/projects/color-thief Install the package via npm. ```bash npm install colorthief ``` -------------------------------- ### Install Color Thief via npm Source: https://lokeshdhakar.com/projects/color-thief Use this command to install the package as a dependency in your project. ```bash $ npm i --save colorthief ``` -------------------------------- ### Swatches API Source: https://lokeshdhakar.com/projects/color-thief Provides methods to get color swatches from an image, categorized by semantic roles like Vibrant, Muted, etc. ```APIDOC ## Swatches API ### Description The `getSwatches()` and `getSwatchesSync()` methods return a `SwatchMap`, which is an object containing up to six semantic color roles. Each role can be either a `Swatch` object or `null` if no color matched that role. ### Methods - `getSwatches(img)`: Asynchronously returns a `SwatchMap`. - `getSwatchesSync(img)`: Synchronously returns a `SwatchMap`. ### SwatchMap Object ```javascript { Vibrant: Swatch | null, Muted: Swatch | null, DarkVibrant: Swatch | null, DarkMuted: Swatch | null, LightVibrant: Swatch | null, LightMuted: Swatch | null, } ``` ### Swatch Object - **color** (`Color`): The extracted color for this role. - **role** (`string`): The semantic role (e.g., 'Vibrant', 'Muted'). - **titleTextColor** (`Color`): Recommended color for title text. - **bodyTextColor** (`Color`): Recommended color for body text. ### Example Usage ```javascript const swatches = getSwatchesSync(img); if (swatches.Vibrant) { document.body.style.background = swatches.Vibrant.color.css(); document.body.style.color = swatches.Vibrant.bodyTextColor.css(); title.style.color = swatches.Vibrant.titleTextColor.css(); } if (swatches.DarkMuted) { sidebar.style.background = swatches.DarkMuted.color.css(); sidebar.style.color = swatches.DarkMuted.bodyTextColor.css(); } ``` ### Swatch Roles - **Vibrant**: Bright, saturated colors. Good for primary accents. - **Muted**: Desaturated, medium brightness. Good for backgrounds. - **DarkVibrant**: Saturated and dark. Good for status bars, headers. - **DarkMuted**: Desaturated and dark. Good for text backgrounds. - **LightVibrant**: Saturated and light. Good for highlights, hover states. - **LightMuted**: Desaturated and light. Good for card backgrounds, borders. ``` -------------------------------- ### Observe Video Source for Palette Updates Source: https://lokeshdhakar.com/projects/color-thief Reactively watches a video source and gets palette updates on every frame. Works with `