npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

reactive-image-colors

v0.2.0

Published

Extract semantic colors from images for reactive UI themes

Readme

reactive-image-colors

Extract semantic colors (accent, light, dark) from images to build reactive, image-driven UI themes.

Installation & Usage

  1. Install:

Using npm package:

        npm i reactive-image-colors

OR cloning the project on local machine:

        git clone https://github.com/codex-leo/reactive-image-colors.git

        cd reactive-image-colors
        
        npm install
  1. Usage:
    • Using in simple js/ts application:
        import { extractColors } from 'reactive-image-colors';

        const colors = await extractColors('path/to/image.jpg');
        console.log(colors);
  • This will log an object containing the accent, light, dark colors and palette extracted from the image.

  • The output will look like this:

        {
          accent: '#ff5733',
          contrast: {
            onAccent: { text: '#000000', bg: '#ff5733'},
            onLight: { text: '#000000', bg: '#f0e68c'},
            onDark: { text: '#ffffff', bg: '#2f4f4f'}
          }
          light: '#f0e68c',
          dark: '#2f4f4f',
          palette: ['#ff5733', '#33ff57', '#3357ff', '#f0e68c', '#2f4f4f', '#8b4513'] //6 most prominent colors
        }
  1. React Hook Usage:

    • You can also use the provided React hook to extract colors in a React component.

    • Hook useImageColors: This hook accepts two parameters: image source (URL or HTMLImageElement) and options. (Refer extractColors function section for available options in detailed documentation on github repository.)

    import { useImageColors } from "reactive-image-colors/react";

    export default function AlbumCard() {
    const imageUrl =
    "https://images.example.com/album-cover.jpg";

    const { colors, loading } = useImageColors(imageUrl, {
        mode: "music"
    });

    if (loading) {
     return <div>Extracting colors...</div>;
    }

    return (
        <div
        style={{
            backgroundColor: colors?.contrast.onAccent.bg,
            color: colors?.contrast.onAccent.text,
            padding: "1rem",
            borderRadius: "12px"
        }}
        >
      <h2>Album Colors</h2>

      <p>Accent: {colors?.accent}</p>
      <p>Light: {colors?.light}</p>
      <p>Dark: {colors?.dark}</p>

      <p>
        Palette: {colors?.palette?.join(", ")}
      </p>
    </div>
  );
}
  • This hook returns an object containing:
    {
        colors: {
            accent: string
            contrast: {
                onAccent: { text: string, bg: string },
                onLight: { text: string, bg: string },
                onDark: { text: string, bg: string }
            }
            light: string
            dark: string
            palette: string[]
        } | null
        loading: boolean
    }
  • and also have loading state to indicate if the colors are still being extracted.
  1. Use To Get Background & Text Contrast Pairs:
    • The returned contrast object contains text and background color pairs for each of the extracted colors (accent, light, dark).
    • This is useful for ensuring good readability when using the extracted colors as backgrounds.
    • Example:
        const colors = await extractColors('path/to/image.jpg');

        const accentBg = colors.accent; // or colors.contrast.onAccent.bg;
        const accentText = colors.contrast.onAccent.text;

        // Now you can use accentBg as background color and accentText as text color
        console.log(`Use ${accentText} on background ${accentBg} for good contrast.`);
  • Example Screenshot:
     const imgColors1 = await extractColors(image);
     const imgColors2 = await extractColors(image2);
     const imgColors3 = await extractColors(image3);
     // for each image, you can get text and background pairs like this:
     const accentText1 = imgColors1.contrast.onAccent.text;
     const accentBg1 = imgColors1.contrast.onAccent.bg;
     const accentText2 = imgColors2.contrast.onAccent.text;
     const accentBg2 = imgColors2.contrast.onAccent.bg;
     const accentText3 = imgColors3.contrast.onAccent.text;
     const accentBg3 = imgColors3.contrast.onAccent.bg;

constrast-screenshot

  1. That's it! You can now use reactive-image-colors to extract colors from images and create dynamic, image-driven UIs.

For detailed documentation, please refer this project's github repository: GITHUB REPOSITORY