Lib: Update server-side image compression
This commit is contained in:
@ -7,17 +7,21 @@ import sharp from "sharp";
|
||||
*/
|
||||
export const image_to_avif = async (
|
||||
data: ArrayBuffer,
|
||||
width: number | undefined = undefined,
|
||||
height: number | undefined = undefined,
|
||||
width?: number,
|
||||
height?: number,
|
||||
quality: number = 50,
|
||||
effort: number = 4,
|
||||
): Promise<Blob> => {
|
||||
console.log(
|
||||
`Compressing ${data.byteLength} Bytes to ${width ?? -1}x${height ?? -1} avif with quality ${quality} and effort ${effort}...`,
|
||||
);
|
||||
|
||||
const compressed: Buffer = await sharp(data)
|
||||
.resize(width, height)
|
||||
.avif({ quality: quality, effort: effort })
|
||||
.toBuffer();
|
||||
|
||||
console.log(`image_to_avif: ${data.byteLength} Bytes -> ${compressed.length} Bytes`);
|
||||
console.log(`Compressed ${data.byteLength} Bytes to ${compressed.length} Bytes`);
|
||||
|
||||
return new Blob([compressed]);
|
||||
};
|
||||
|
Reference in New Issue
Block a user