MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Functions
jq Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

getColorFromImage

The getColorFromImage function extracts the dominant color from an image. You can use the extracted color with the setColorScheme function to create dynamic color schemes.

Usage

Import the function:

import { getColorFromImage } from 'mdui/functions/getColorFromImage.js';

Example:

const image = new Image();
image.src = 'demo.png';

getColorFromImage(image).then((color) => {
  console.log(color);
});

API

getColorFromImage(image: string | HTMLImageElement | JQ<HTMLImageElement>): Promise<string>

This function takes a CSS selector for an <img> element, an HTMLImageElement object, or a JQ object representing an <img> element as its parameter.

It returns a Promise that resolves to the hexadecimal color value of the dominant color in the image (e.g., #ff0000).

On this page