Created
December 28, 2014 00:10
-
-
Save paddlefish/5f2fa0abc75310adc785 to your computer and use it in GitHub Desktop.
Resize Vector source image for AppIcon
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
import re | |
import json | |
from subprocess import call | |
from pprint import pprint | |
for iconset in ['Design Show Server/Images.xcassets/AppIcon.appiconset', 'Design Show/Images.xcassets/AppIcon.appiconset']: | |
json_data=open(iconset + '/Contents.json') | |
newdata = [] | |
data = json.load(json_data) | |
for img in data["images"]: | |
size = int(re.sub(r'x.+$','', img["size"])) | |
filename='{idiom:s}_{size:d}_{scale}.png'.format(idiom=img["idiom"],scale=img["scale"],size=size) | |
filepath='{iconset:s}/{filename:s}'.format(iconset=iconset,filename=filename) | |
if img["scale"] == '2x': | |
size = size * 2 | |
newdata.append({ "filename" : filename, "size" : img["size"], "idiom" : img["idiom"], "scale" :img["scale"] }) | |
print('{filename:s} {size:d}'.format(filename=filename,size=size)) | |
call(['sips', '-s', 'format', 'png', '-Z', str(size), '-o', filepath, 'icon.pdf']) | |
json_data.close() | |
contents_file = open(iconset + '/Contents.json', "w") | |
contents_file.write( json.dumps({ "images" : newdata, "info" : { "version" : 1, "author" : "andy's python script" }}) ) | |
contents_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment