diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index c53f010..3770f1d 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -69,13 +69,13 @@ async function main() { yoga.handleNodeRequestAndResponse(req, reply, { req, reply, db, redis }), }); - // Transform presets: width x height (height optional = keep aspect ratio) - const TRANSFORMS: Record = { - mini: { width: 64, height: 64 }, - thumbnail: { width: 200, height: 200 }, - preview: { width: 480, height: 270 }, - medium: { width: 960 }, - banner: { width: 1280, height: 400 }, + // Transform presets — only banner/thumbnail force a crop; others preserve aspect ratio + const TRANSFORMS: Record = { + mini: { width: 80, height: 80, fit: "cover" }, + thumbnail: { width: 300, height: 300, fit: "cover" }, + preview: { width: 800, fit: "inside" }, + medium: { width: 1400, fit: "inside" }, + banner: { width: 1600, height: 480, fit: "cover" }, }; // Serve uploaded files: GET /assets/:id?transform= @@ -101,8 +101,8 @@ async function main() { if (!existsSync(cacheFile)) { const originalPath = path.join(UPLOAD_DIR, id, filename); await sharp(originalPath) - .resize({ width: preset.width, height: preset.height, fit: "cover", withoutEnlargement: true }) - .webp({ quality: 85 }) + .resize({ width: preset.width, height: preset.height, fit: preset.fit ?? "inside", withoutEnlargement: true }) + .webp({ quality: 92 }) .toFile(cacheFile); } reply.header("Content-Type", "image/webp");