Created
November 1, 2017 01:01
-
-
Save dlo/1da76cdb601b6fbd593b5af42c7e9b95 to your computer and use it in GitHub Desktop.
Automatically generate a Content.json file for an iOS icon set from a list of iOS icons in a folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Usage: ls *.png | ./generate_iconset_contents.py | |
import sys | |
import re | |
import json | |
r = re.compile(".*(AppStore|iPhone|iPad).*-([\d\.]+)(@\dx)?\.png") | |
idioms = { | |
'AppStore': "ios-marketing", | |
'iPhone': "iphone", | |
'iPad': "ipad" | |
} | |
items = { | |
'images': [], | |
'info': { | |
'version': 1, | |
'author': "xcode", | |
} | |
} | |
filenames = sys.stdin | |
for filename in filenames: | |
match = r.match(filename) | |
groups = match.groups() | |
item = { | |
'filename': filename.strip(), | |
'idiom': idioms[groups[0]], | |
'size': "{0}x{0}".format(groups[1]), | |
} | |
if groups[2]: | |
item['scale'] = groups[2][1:] | |
else: | |
item['scale'] = '1x' | |
items['images'].append(item) | |
with open("Contents.json", 'w') as f: | |
json.dump(items, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment