fp/packages/scout/src/image.js

16 lines
356 B
JavaScript
Raw Normal View History

2024-06-04 23:06:47 +00:00
// import ColorThief from 'colorthief'
import sharp from 'sharp'
export async function getProminentColor(imageFile) {
const { dominant } = await sharp(imageFile).stats();
const { r, g, b } = dominant;
return rgbToHex(r, g, b)
}
export function rgbToHex(r, g, b) {
return "#" + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);
}