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 {
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}
You can’t perform that action at this time.
0 commit comments