@@ -71,24 +71,29 @@ export class AssetsGenerationService implements IAssetsGenerationService {
71
71
const outputPath = assetItem . path ;
72
72
const width = assetItem . width * scale ;
73
73
const height = assetItem . height * scale ;
74
-
74
+ let image : Jimp ;
75
75
switch ( operation ) {
76
76
case Operations . OverlayWith :
77
77
const overlayImageScale = assetItem . overlayImageScale || AssetConstants . defaultOverlayImageScale ;
78
78
const imageResize = Math . round ( Math . min ( width , height ) * overlayImageScale ) ;
79
- const image = await this . resize ( generationData . imagePath , imageResize , imageResize ) ;
80
- await this . generateImage ( generationData . background , width , height , outputPath , image ) ;
79
+ image = await this . resize ( generationData . imagePath , imageResize , imageResize ) ;
80
+ image = this . generateImage ( generationData . background , width , height , outputPath , image ) ;
81
81
break ;
82
82
case Operations . Blank :
83
- await this . generateImage ( generationData . background , width , height , outputPath ) ;
83
+ image = this . generateImage ( generationData . background , width , height , outputPath ) ;
84
84
break ;
85
85
case Operations . Resize :
86
- const resizedImage = await this . resize ( generationData . imagePath , width , height ) ;
87
- resizedImage . write ( outputPath ) ;
86
+ image = await this . resize ( generationData . imagePath , width , height ) ;
88
87
break ;
89
88
default :
90
89
throw new Error ( `Invalid image generation operation: ${ operation } ` ) ;
91
90
}
91
+
92
+ if ( assetItem . rgba === false ) {
93
+ image = image . rgba ( false ) ;
94
+ }
95
+
96
+ image . write ( outputPath ) ;
92
97
}
93
98
}
94
99
@@ -97,7 +102,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
97
102
return image . scaleToFit ( width , height ) ;
98
103
}
99
104
100
- private generateImage ( background : string , width : number , height : number , outputPath : string , overlayImage ?: Jimp ) : void {
105
+ private generateImage ( background : string , width : number , height : number , outputPath : string , overlayImage ?: Jimp ) : Jimp {
101
106
// Typescript declarations for Jimp are not updated to define the constructor with backgroundColor so we workaround it by casting it to <any> for this case only.
102
107
const J = < any > Jimp ;
103
108
const backgroundColor = this . getRgbaNumber ( background ) ;
@@ -109,7 +114,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
109
114
image = image . composite ( overlayImage , centeredWidth , centeredHeight ) ;
110
115
}
111
116
112
- image . write ( outputPath ) ;
117
+ return image ;
113
118
}
114
119
115
120
private getRgbaNumber ( colorString : string ) : number {
0 commit comments