16 lines
356 B
JavaScript
16 lines
356 B
JavaScript
|
// 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);
|
||
|
}
|