11import * as Jimp from "jimp" ;
22import * as Color from "color" ;
33import { exported } from "../../common/decorators" ;
4+ import { AssetConstants } from '../../constants' ;
45
56export const enum Operations {
67 OverlayWith = "overlayWith" ,
@@ -39,12 +40,12 @@ export class AssetsGenerationService implements IAssetsGenerationService {
3940 const assetsStructure = await this . $projectDataService . getAssetsStructure ( generationData ) ;
4041
4142 const assetItems = _ ( assetsStructure )
42- . filter ( ( assetGroup : IAssetGroup , platform : string ) => {
43- return ! generationData . platform || platform . toLowerCase ( ) === generationData . platform . toLowerCase ( ) ;
44- } )
43+ . filter ( ( assetGroup : IAssetGroup , platform : string ) =>
44+ ! generationData . platform || platform . toLowerCase ( ) === generationData . platform . toLowerCase ( )
45+ )
4546 . map ( ( assetGroup : IAssetGroup ) =>
4647 _ . filter ( assetGroup , ( assetSubGroup : IAssetSubGroup , imageTypeKey : string ) =>
47- propertiesToEnumerate . indexOf ( imageTypeKey ) !== - 1 && ! assetSubGroup [ imageTypeKey ]
48+ assetSubGroup && propertiesToEnumerate . indexOf ( imageTypeKey ) !== - 1
4849 )
4950 )
5051 . flatten < IAssetSubGroup > ( )
@@ -55,20 +56,34 @@ export class AssetsGenerationService implements IAssetsGenerationService {
5556
5657 for ( const assetItem of assetItems ) {
5758 const operation = assetItem . resizeOperation || Operations . Resize ;
58- const scale = assetItem . scale || 0.8 ;
59+ let tempScale : number = null ;
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+ }
67+ }
68+
69+ const scale = tempScale || AssetConstants . defaultScale ;
70+
5971 const outputPath = assetItem . path ;
72+ const width = assetItem . width * scale ;
73+ const height = assetItem . height * scale ;
6074
6175 switch ( operation ) {
6276 case Operations . OverlayWith :
63- const imageResize = Math . round ( Math . min ( assetItem . width , assetItem . height ) * scale ) ;
77+ const overlayImageScale = assetItem . overlayImageScale || AssetConstants . defaultOverlayImageScale ;
78+ const imageResize = Math . round ( Math . min ( width , height ) * overlayImageScale ) ;
6479 const image = await this . resize ( generationData . imagePath , imageResize , imageResize ) ;
65- await this . generateImage ( generationData . background , assetItem . width , assetItem . height , outputPath , image ) ;
80+ await this . generateImage ( generationData . background , width , height , outputPath , image ) ;
6681 break ;
6782 case Operations . Blank :
68- await this . generateImage ( generationData . background , assetItem . width , assetItem . height , outputPath ) ;
83+ await this . generateImage ( generationData . background , width , height , outputPath ) ;
6984 break ;
7085 case Operations . Resize :
71- const resizedImage = await this . resize ( generationData . imagePath , assetItem . width , assetItem . height ) ;
86+ const resizedImage = await this . resize ( generationData . imagePath , width , height ) ;
7287 resizedImage . write ( outputPath ) ;
7388 break ;
7489 default :
0 commit comments