@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";
let colors = await getImageColors("./sample.jpg");
colors.map(c => c.background);
colors.map(c => c.colorjs.toString({format: "hex"}));
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,
foreground,
colorjs,
mode,
contrast: {
light,
dark,
},
toString(),
}]
Learn more about color.js Color objects.