mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 11:12:06 +10:00
16 lines
465 B
TypeScript
16 lines
465 B
TypeScript
import sharp from 'sharp';
|
|
|
|
export const resizeAndCompressImage = async (imageBuffer: Buffer): Promise<Buffer> => {
|
|
const metadata = await sharp(imageBuffer).metadata();
|
|
const originalWidth = metadata.width || 0;
|
|
|
|
if (originalWidth > 1000) {
|
|
return await sharp(imageBuffer)
|
|
.resize({ width: 1000, withoutEnlargement: true })
|
|
.jpeg({ quality: 70 })
|
|
.toBuffer();
|
|
}
|
|
|
|
return await sharp(imageBuffer).jpeg({ quality: 70 }).toBuffer();
|
|
};
|