Skip to content

Commit 8375a68

Browse files
committed
Merge branch 'main' of github.com:MobileTeleSystems/image-optimize
2 parents aee780c + 76049f4 commit 8375a68

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/services/optimize.service.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,12 @@ export class OptimizeService {
1212
format: Formats,
1313
quality?: number,
1414
): Promise<Buffer> {
15-
let img = sharp(imgBuffer);
15+
const img = sharp(imgBuffer);
1616
const { width: sourceWidth } = await img.metadata();
1717

1818
// Math.min prevent grow image to biggest width
1919
img.resize({ width: Math.min(sourceWidth, width) });
2020

21-
if (format === Formats.Webp) {
22-
img = img.webp({ quality });
23-
} else if (format === Formats.Avif) {
24-
img = img.avif({ quality });
25-
} else if (format === Formats.Png) {
26-
img = img.png({ quality });
27-
} else if (format === Formats.Jpeg) {
28-
img = img.jpeg({ quality });
29-
}
30-
31-
return await img.toBuffer();
21+
return await img[format]({ quality }).toBuffer();
3222
}
3323
}

0 commit comments

Comments
 (0)