getColorFromImage

The getColorFromImage function is designed to extract the dominant color from an image. The extracted color can be used in conjunction with the setColorScheme function to implement dynamic color functionality.

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).

MDUIDocsEnglish简体中文LightDarkSystem
Preset Colors
Custom Color
Extract Color from Wallpaper
Select a Wallpaper
Getting Started
Introduction Installation Usage TypeScript Support IDE Support Localization Frequently Asked Questions
Styles
Dark Theme Dynamic Theme Typography Design Tokens
Frameworks
React Vue Angular
Components
Button ButtonIcon Fab SegmentedButton Chip Card Checkbox Radio Switch Slider RangeSlider List Collapse Tabs Dropdown Menu Select TextField LinearProgress CircularProgress Dialog Divider Avatar Badge Icon Tooltip Snackbar NavigationBar NavigationDrawer NavigationRail BottomAppBar TopAppBar Layout
Functions
JavaScript Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries
@mdui/icons