import sharp from "sharp"; import { screenshotLimit } from "../shared/bug-reports"; export async function supportScreenshot(bytes: Uint8Array) { if (!bytes.length || bytes.length > screenshotLimit) throw new Error("Use a screenshot smaller than 5 MB"); const image = sharp(bytes, { limitInputPixels: 24_000_000, failOn: "error", animated: false, }); const meta = await image.metadata(); if ( !["png", "jpeg", "webp"].includes(meta.format ?? "") || (meta.pages ?? 1) !== 1 ) throw new Error("Choose a PNG, JPG, or WebP screenshot"); return image .rotate() .resize({ width: 2400, height: 2400, fit: "inside", withoutEnlargement: true, }) .webp({ quality: 85 }) .toBuffer(); }