Skip to content

Commit

Permalink
option to use different image for splash
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jul 21, 2017
1 parent 061afec commit b5d5788
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
14 changes: 8 additions & 6 deletions build/icons.py
Expand Up @@ -172,15 +172,17 @@ def sortkey(size):
else:
width, height = (int(s) for s in size.split('x'))
minsize = min(width, height)
minsize = min(minsize, img.width, img.height)
minsize = min(minsize, max(img.width, img.height))

icon = img.copy()
icon.thumbnail((minsize, minsize), Image.ANTIALIAS)
if width != minsize or height != minsize:
left = (width - minsize) // 2
right = width - minsize - left
top = (height - minsize) // 2
bottom = height - minsize - top
if icon.width < width or icon.height < height:
lrpad = (width - icon.width)
left = lrpad // 2
right = lrpad - left
tbpad = (height - icon.height)
top = tbpad // 2
bottom = tbpad - top
fill = img.load()[0, 0]
icon = ImageOps.expand(icon, (left, top, right, bottom), fill)

Expand Down
20 changes: 13 additions & 7 deletions build/phonegap.py
Expand Up @@ -14,6 +14,10 @@
'--source', type=click.Path(), help="Directory containing app assets"
)
@click.option('--icon', type=click.Path(), help="Source image for icons")
@click.option(
'--splash', type=click.Path(),
help="Source image for splash screen (defaults to icon)",
)
@click.option('--config-xml', type=click.Path(), help="config.xml template")
@click.option('--index-html', type=click.Path(), help="index.html template")
@click.option(
Expand Down Expand Up @@ -89,6 +93,7 @@ def phonegap(ctx, config, version, **conf):
version=version,
context=ctx,
icon=conf['icon'],
splash=conf['splash'] or conf['icon'],
config_xml=conf['config_xml'],
index_html=conf['index_html'],
)
Expand All @@ -102,7 +107,7 @@ def phonegap(ctx, config, version, **conf):


def create_zipfile(directory, source, version, context,
icon=None, config_xml=None, index_html=None):
icon=None, splash=None, config_xml=None, index_html=None):
folder = os.path.join(directory, 'build')
if os.path.exists(folder):
shutil.rmtree(folder)
Expand All @@ -112,13 +117,14 @@ def create_zipfile(directory, source, version, context,
'version': version,
}

if icon:
if icon or splash:
icon_dir = 'icons'
filename = '{alias}.png'
platforms = (
'android', 'ios', 'windows',
'android-splash', 'ios-splash', 'windows-splash'
)
platforms = tuple()
if icon:
platforms += ('android', 'ios', 'windows')
if splash:
platforms += ('android-splash', 'ios-splash', 'windows-splash')

icon_path = os.path.join(directory, 'build', icon_dir)
os.mkdir(icon_path)
Expand All @@ -143,7 +149,7 @@ def get_height(size):
for platform in platforms:
context.invoke(
icons,
source=icon,
source=splash if platform.endswith('splash') else icon,
outdir=icon_path,
filename=filename,
size=[platform],
Expand Down

0 comments on commit b5d5788

Please sign in to comment.