mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(api): add resize, crop, rotate, convert, compress, metadata, and color tool routes
Seven tool route files using the createToolRoute factory, registering 10 API endpoints total (color adjustments covers 4 tool IDs). Also fixes the tool factory generic to properly infer Zod output types and clamps the compress binary-search quality to 1-100.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
import { createToolRoute } from "../tool-factory.js";
|
||||
import { crop } from "@stirling-image/image-engine";
|
||||
import sharp from "sharp";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
const settingsSchema = z.object({
|
||||
left: z.number().int().min(0),
|
||||
top: z.number().int().min(0),
|
||||
width: z.number().int().positive(),
|
||||
height: z.number().int().positive(),
|
||||
});
|
||||
|
||||
export function registerCrop(app: FastifyInstance) {
|
||||
createToolRoute(app, {
|
||||
toolId: "crop",
|
||||
settingsSchema,
|
||||
process: async (inputBuffer, settings, filename) => {
|
||||
const image = sharp(inputBuffer);
|
||||
const result = await crop(image, settings);
|
||||
const buffer = await result.toBuffer();
|
||||
return { buffer, filename, contentType: "image/png" };
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user