Skip to content

Commit e173c2d

Browse files
authored
Merge pull request #4632 from NativeScript/kddimitrov/fix-app-store-icon-rgba
fix: generated App Store icon has alpha channel
2 parents b859af0 + 81ca059 commit e173c2d

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-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

+14-8
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,30 @@ 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+
// This code disables the alpha chanel, as some images for the Apple App Store must not have transparency.
93+
if (assetItem.rgba === false) {
94+
image = image.rgba(false);
95+
}
96+
97+
image.write(outputPath);
9298
}
9399
}
94100

@@ -97,7 +103,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
97103
return image.scaleToFit(width, height);
98104
}
99105

100-
private generateImage(background: string, width: number, height: number, outputPath: string, overlayImage?: Jimp): void {
106+
private generateImage(background: string, width: number, height: number, outputPath: string, overlayImage?: Jimp): Jimp {
101107
// 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.
102108
const J = <any>Jimp;
103109
const backgroundColor = this.getRgbaNumber(background);
@@ -109,7 +115,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
109115
image = image.composite(overlayImage, centeredWidth, centeredHeight);
110116
}
111117

112-
image.write(outputPath);
118+
return image;
113119
}
114120

115121
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)