Files
enchanced-twitch-panel/builder/images.js
T
Ku6epXBOCTuK b1b4d29803
publish-content / build (push) Canceled after 0s
feat: initial version
2026-09-05 20:39:54 +05:00

19 lines
617 B
JavaScript

import sharp from 'sharp';
import crypto from 'node:crypto';
import fs from 'node:fs/promises';
import path from 'node:path';
export async function hashFile(p) {
const buf = await fs.readFile(p);
return crypto.createHash('sha256').update(buf).digest('hex').slice(0, 8);
}
export async function optimizeImage(src, dest, { width = 640, height = null } = {}) {
await fs.mkdir(path.dirname(dest), { recursive: true });
let img = sharp(src);
img = height
? img.resize(width, height, { fit: 'cover' })
: img.resize({ width, withoutEnlargement: true });
await img.webp({ quality: 80 }).toFile(dest);
}