New:Socket for Asana Is Now Available.Learn more
Get Started

@11ty/image-color

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/image-color

Small utility to efficiently fetch the colors from an image.

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
244
201.23%
Maintainers
2
Weekly downloads
 
Created
Source

@11ty/image-color

A small utility to efficiently extract color information from images (with a memoization and a disk-cache). Requires Node 18 or newer.

Installation

Install from npm:

npm install @11ty/image-color

Usage

import { getImageColors } from "@11ty/image-color";

// Returns an array of color objects
let colors = await getImageColors("./sample.jpg");

// Works with local or remote images
// let colors = await getImageColors("https://example.com/sample.jpg");

// Get oklch values
colors.map(c => c.background);

// Get hex values
colors.map(c => c.colorjs.toString({format: "hex"}));

// Filter colors based on Lightness value
colors.filter(c => c.colorjs.oklch.l > .1);

Learn more about color.js Color objects.

Returns

An array of colors in the image, with the following properties:

[{
	background, // oklch color string (you probably want this)
	foreground, // accessible color for text on top

	colorjs, // colorjs.io Color object

	mode, // one of "dark" or "light", based on WCAG21 contrast versus #000 or #fff
	contrast: {
		light, // WCAG21 contrast color (number) versus white (#fff) (4.5+ is good)
		dark, // WCAG21 contrast color (number) versus black (#000) (4.5+ is good)
	},

	toString(), // returns same as `background`
}]

Learn more about color.js Color objects.

FAQs

Package last updated on 25 Feb 2025

Related posts