File tree Expand file tree Collapse file tree 1 file changed +2
-12
lines changed Expand file tree Collapse file tree 1 file changed +2
-12
lines changed Original file line number Diff line number Diff line change @@ -12,22 +12,12 @@ export class OptimizeService {
12
12
format : Formats ,
13
13
quality ?: number ,
14
14
) : Promise < Buffer > {
15
- let img = sharp ( imgBuffer ) ;
15
+ const img = sharp ( imgBuffer ) ;
16
16
const { width : sourceWidth } = await img . metadata ( ) ;
17
17
18
18
// Math.min prevent grow image to biggest width
19
19
img . resize ( { width : Math . min ( sourceWidth , width ) } ) ;
20
20
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 ( ) ;
32
22
}
33
23
}
You can’t perform that action at this time.
0 commit comments