// import ColorThief from 'colorthief'; import sharp from 'sharp'; import Prevvy from 'prevvy'; import path from 'path'; import { getTmpFile } from 'utils'; export async function getProminentColor(imageFile: string): Promise { const { dominant } = await sharp(imageFile).stats(); const { r, g, b } = dominant; return rgbToHex(r, g, b); } export function rgbToHex(r: number, g: number, b: number): string { return "#" + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1); } export async function getStoryboard(imageFileOrUrl: string): Promise { let base = path.basename(imageFileOrUrl); let outputImagePath = getTmpFile(base); let options = { input: imageFileOrUrl, output: outputImagePath, width: 265, cols: 5, rows: 5, }; let prevvy = new Prevvy(options); await prevvy.generate(); return outputImagePath; }