Skip to content

Commit 2b2f64c

Browse files
committed
fix: generated App Store icon has alpha channel
1 parent b859af0 commit 2b2f64c

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ interface IAssetItem {
212212
idiom: string;
213213
resizeOperation?: string;
214214
overlayImageScale?: number;
215+
rgba?: boolean;
215216
}
216217

217218
interface IAssetSubGroup {

lib/services/assets-generation/assets-generation-service.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,29 @@ export class AssetsGenerationService implements IAssetsGenerationService {
7171
const outputPath = assetItem.path;
7272
const width = assetItem.width * scale;
7373
const height = assetItem.height * scale;
74-
74+
let image: Jimp;
7575
switch (operation) {
7676
case Operations.OverlayWith:
7777
const overlayImageScale = assetItem.overlayImageScale || AssetConstants.defaultOverlayImageScale;
7878
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);
8181
break;
8282
case Operations.Blank:
83-
await this.generateImage(generationData.background, width, height, outputPath);
83+
image = this.generateImage(generationData.background, width, height, outputPath);
8484
break;
8585
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);
8887
break;
8988
default:
9089
throw new Error(`Invalid image generation operation: ${operation}`);
9190
}
91+
92+
if (assetItem.rgba === false) {
93+
image = image.rgba(false);
94+
}
95+
96+
image.write(outputPath);
9297
}
9398
}
9499

@@ -97,7 +102,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
97102
return image.scaleToFit(width, height);
98103
}
99104

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 {
101106
// 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.
102107
const J = <any>Jimp;
103108
const backgroundColor = this.getRgbaNumber(background);
@@ -109,7 +114,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
109114
image = image.composite(overlayImage, centeredWidth, centeredHeight);
110115
}
111116

112-
image.write(outputPath);
117+
return image;
113118
}
114119

115120
private getRgbaNumber(colorString: string): number {

lib/services/project-data-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export class ProjectDataService implements IProjectDataService {
252252
image.resizeOperation = image.resizeOperation || assetItem.resizeOperation;
253253
image.overlayImageScale = image.overlayImageScale || assetItem.overlayImageScale;
254254
image.scale = image.scale || assetItem.scale;
255+
image.rgba = assetItem.rgba;
255256
// break each
256257
return false;
257258
}

resources/assets/image-definitions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
"height": 1024,
140140
"directory": "Assets.xcassets/AppIcon.appiconset",
141141
"filename": "icon-1024.png",
142-
"scale": "1x"
142+
"scale": "1x",
143+
"rgba": false
143144
}
144145
],
145146
"splashBackgrounds": [

0 commit comments

Comments
 (0)