Skip to content

Commit c9d4d8f

Browse files
fix(assets): Improve image definitions for iOS
Set correct sizes for iOS images in image-definitions.json. Also fix the code that resizes the images and overlay images. Add option to have overlayImageScale in the json. We've not set it now, but the code will respect it in case we decide to add it.
1 parent 35e2594 commit c9d4d8f

File tree

4 files changed

+138
-89
lines changed

4 files changed

+138
-89
lines changed

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ interface IAssetItem {
160160
scale: string;
161161
idiom: string;
162162
resizeOperation?: string;
163+
overlayImageScale?: number;
163164
}
164165

165166
interface IAssetSubGroup {

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
4545
)
4646
.map((assetGroup: IAssetGroup) =>
4747
_.filter(assetGroup, (assetSubGroup: IAssetSubGroup, imageTypeKey: string) =>
48-
assetSubGroup && propertiesToEnumerate.indexOf(imageTypeKey) !== -1 && assetSubGroup[imageTypeKey]
48+
assetSubGroup && propertiesToEnumerate.indexOf(imageTypeKey) !== -1
4949
)
5050
)
5151
.flatten<IAssetSubGroup>()
@@ -57,26 +57,33 @@ export class AssetsGenerationService implements IAssetsGenerationService {
5757
for (const assetItem of assetItems) {
5858
const operation = assetItem.resizeOperation || Operations.Resize;
5959
let tempScale: number = null;
60-
if (assetItem.scale && !_.isNumber(assetItem.scale)) {
61-
const splittedElements = `${assetItem.scale}`.split(AssetConstants.sizeDelimiter);
62-
tempScale = splittedElements && splittedElements.length && splittedElements[0] && +splittedElements[0];
60+
if (assetItem.scale) {
61+
if (_.isNumber(assetItem.scale)) {
62+
tempScale = assetItem.scale;
63+
} else {
64+
const splittedElements = `${assetItem.scale}`.split(AssetConstants.sizeDelimiter);
65+
tempScale = splittedElements && splittedElements.length && splittedElements[0] && +splittedElements[0];
66+
}
6367
}
6468

65-
const scale = tempScale || 0.8;
69+
const scale = tempScale || 1;
6670

6771
const outputPath = assetItem.path;
72+
const width = assetItem.width * scale;
73+
const height = assetItem.height * scale;
6874

6975
switch (operation) {
7076
case Operations.OverlayWith:
71-
const imageResize = Math.round(Math.min(assetItem.width, assetItem.height) * scale);
77+
const overlayImageScale = assetItem.overlayImageScale || 0.8;
78+
const imageResize = Math.round(Math.min(width, height) * overlayImageScale);
7279
const image = await this.resize(generationData.imagePath, imageResize, imageResize);
73-
await this.generateImage(generationData.background, assetItem.width, assetItem.height, outputPath, image);
80+
await this.generateImage(generationData.background, width, height, outputPath, image);
7481
break;
7582
case Operations.Blank:
76-
await this.generateImage(generationData.background, assetItem.width, assetItem.height, outputPath);
83+
await this.generateImage(generationData.background, width, height, outputPath);
7784
break;
7885
case Operations.Resize:
79-
const resizedImage = await this.resize(generationData.imagePath, assetItem.width, assetItem.height);
86+
const resizedImage = await this.resize(generationData.imagePath, width, height);
8087
resizedImage.write(outputPath);
8188
break;
8289
default:

lib/services/project-data-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export class ProjectDataService implements IProjectDataService {
159159
image.size = image.size || `${assetItem.width}${AssetConstants.sizeDelimiter}${assetItem.height}`;
160160
}
161161

162+
image.resizeOperation = image.resizeOperation || assetItem.resizeOperation;
163+
image.overlayImageScale = image.overlayImageScale || assetItem.overlayImageScale;
164+
162165
// break each
163166
return false;
164167
}

0 commit comments

Comments
 (0)