rooooms
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user