This commit is contained in:
2025-09-03 14:32:02 -04:00
parent c6e2b6e4d3
commit 03b751dda6
22 changed files with 1429 additions and 150 deletions

View File

@@ -13,9 +13,7 @@ export const route = createHonoRoute('/img');
async function convertImage(query: {cropSquare?: boolean | undefined;width?: number | undefined;height?: number | undefined;}, data: Uint8Array<ArrayBufferLike>): Promise<Uint8Array<ArrayBufferLike>> {
const image = sharp(data);
const rootMetadata = await image.metadata();
const rootWidth = rootMetadata.width;
const rootHeight = rootMetadata.height;
const squareSize = Math.min(rootWidth, rootHeight);
const squareSize = Math.min(rootMetadata.width, rootMetadata.height);
if (query.cropSquare) image.resize(squareSize, squareSize);
const newImage = sharp(await image.png().toBuffer());
@@ -34,8 +32,8 @@ const imgNameParamSchema = z.object({
});
const imgQuerySchema = z.object({
cropSquare: z.coerce.boolean().optional(),
width: z.coerce.number().max(3840).optional(),
height: z.coerce.number().max(2160).optional(),
width: z.coerce.number().min(64).max(3840).optional(),
height: z.coerce.number().min(64).max(2160).optional(),
});
route.app.get('/:imgName',
typedZValidator('param', imgNameParamSchema),