diff --git a/.gitignore b/.gitignore index b6f1ec2..89634ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ venv/ images/ logo.png + +dist/ +assm/__pycache__ diff --git a/assm.py b/assm.py deleted file mode 100644 index fc99720..0000000 --- a/assm.py +++ /dev/null @@ -1,43 +0,0 @@ -import json -from PIL import Image - -def getDevicesList(): - with open('./devicesArrays.json', encoding='utf-8') as f: - raw = f.read() - - return(json.loads(raw)) - -if __name__ == '__main__': - devicesList = getDevicesList() - - # portrait - for device in devicesList: - device_w = devicesList[device][0] - device_h = devicesList[device][1] - device_r = round(device_w / 5) - - image_w_center = round((device_w / 2) - (device_r / 2)) - image_h_center = round((device_h / 2) - (device_r / 2)) - - base_image = Image.new('RGB', (device_w, device_h), (255, 255, 255)) - logo_image = Image.open('./logo.png') - a = logo_image.resize((device_r, device_r)) - base_image.paste(a, (image_w_center, image_h_center), a) - base_image.save('./images/splash-portrait-{width}x{height}.png'.format( - width=device_w, height=device_h)) - - # landscape - for device in devicesList: - device_w = devicesList[device][0] - device_h = devicesList[device][1] - device_r = round(device_w / 5) - - image_w_center = round((device_w / 2) - (device_r / 2)) - image_h_center = round((device_h / 2) - (device_r / 2)) - - base_image = Image.new('RGB', (device_h, device_w), (255, 255, 255)) - logo_image = Image.open('./logo.png') - a = logo_image.resize((device_r, device_r)) - base_image.paste(a, (image_h_center, image_w_center), a) - base_image.save('./images/splash-landscape-{height}x{width}.png'.format( - width=device_w, height=device_h)) diff --git a/assm/__init__.py b/assm/__init__.py new file mode 100644 index 0000000..91a2029 --- /dev/null +++ b/assm/__init__.py @@ -0,0 +1,3 @@ +"""iOS splash screen generator""" + +__version__ = "0.1.11" diff --git a/assm/__main__.py b/assm/__main__.py new file mode 100644 index 0000000..efca70d --- /dev/null +++ b/assm/__main__.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import os +import json +from PIL import Image +from assm.devices import APPLE_DEVICES + +def makeSplashImage(screen_orientation, screen_width, screen_height, logo_path='logo.png'): + """ Generate splash image """ + + # swap screen sizes + if screen_orientation == 'landscape': + screen_width, screen_height = screen_height, screen_width + + logo_size = round(screen_width / 5) + logo_w_pos = round((screen_width / 2) - (logo_size / 2)) + logo_h_pos = round((screen_height / 2) - (logo_size / 2)) + + splash_image = Image.new('RGB', (screen_width, screen_height), (255, 255, 255)) + logo_image = Image.open(logo_path) + app_logo = logo_image.resize((logo_size, logo_size)) + splash_image.paste(app_logo, (logo_w_pos, logo_h_pos), app_logo) + + return(splash_image) + +def main(output_folder='./images/'): + # check folder exists + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + # portrait + print('Generate portrait splash...') + + for device in APPLE_DEVICES: + w = APPLE_DEVICES[device][0] + h = APPLE_DEVICES[device][1] + + file_name = '{folder}/splash-portrait-{height}x{width}.png'.format( + folder=output_folder, width=w, height=h) + + splash = makeSplashImage('portrait', w, h, 'logo.png') + splash.save(file_name) + + print('..splash for {w}x{h} saved...'.format(w=w, h=h)) + + # landscape + print('Generate landscape splash...') + + for device in APPLE_DEVICES: + w = APPLE_DEVICES[device][0] + h = APPLE_DEVICES[device][1] + + file_name = '{folder}/splash-landscape-{height}x{width}.png'.format( + folder=output_folder, width=w, height=h) + + splash = makeSplashImage('landscape', w, h, 'logo.png') + splash.save(file_name) + + print('...splash for {h}x{w} saved...'.format(w=w, h=h)) + +if __name__ == '__main__': + main() diff --git a/assm/devices.py b/assm/devices.py new file mode 100644 index 0000000..b698f3d --- /dev/null +++ b/assm/devices.py @@ -0,0 +1,12 @@ +APPLE_DEVICES = { + 'iPhone SE': [640, 1136], + 'iPhone 6/7/8': [750, 1334], + 'iPhone XR': [828, 1792], + 'iPhone X': [1125, 2436], + 'iPhone 8 Plus': [1242, 2208], + 'iPhone XS Max': [1242, 2688], + '9.7" iPad': [1536, 2048], + '10.5" iPad Pro': [1668, 2224], + '11" iPad Pro': [1668, 2388], + '12.9" iPad Pro': [2048, 2732] +} diff --git a/devicesArrays.json b/devicesArrays.json deleted file mode 100644 index 06e1ebf..0000000 --- a/devicesArrays.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "iPhone SE": [640, 1136], - "iPhone 6/7/8": [750, 1334], - "iPhone XR": [828, 1792], - "iPhone X": [1125, 2436], - "iPhone 8 Plus": [1242, 2208], - "iPhone XS Max": [1242, 2688], - "9.7\" iPad": [1536, 2048], - "10.5\" iPad Pro": [1668, 2224], - "11\" iPad Pro": [1668, 2388], - "12.9\" iPad Pro": [2048, 2732] -} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8a6ef43 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[build-system] +requires = ["flit_core >=2,<4"] +build-backend = "flit_core.buildapi" + +[tool.flit.metadata] +module = "assm" +author = "Alexander Popov" +author-email = "iiiypuk@iiiypuk.me" +home-page = "https://github.com/emilecok/assm" +requires-python = ">=3" +requires = ["Pillow==8.1.0" ] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3" +] +description-file = "README.md"