File indexing completed on 2024-03-24 15:14:09
0001 #!/usr/bin/python 0002 # 0003 # GCompris - createAppicon.py 0004 # 0005 # SPDX-FileCopyrightText: 2015 Bruno Coudoin <bruno.coudoin@gcompris.net> 0006 # 0007 # SPDX-License-Identifier: GPL-3.0-or-later 0008 0009 import json 0010 import subprocess 0011 import sys 0012 import os 0013 0014 if len(sys.argv) < 3: 0015 print 'Usage: createAppicon.py Images.xcassets/AppIcon.appiconset icon_no_corner.svg' 0016 sys.exit(1) 0017 0018 outdir = sys.argv[1] 0019 image_source = sys.argv[2] 0020 0021 try: 0022 os.makedirs(outdir) 0023 except: 0024 pass 0025 0026 images = [ 0027 [ 29, "iphone", 1 ], 0028 [ 29, "iphone", 2 ], 0029 [ 29, "iphone", 3 ], 0030 [ 40, "iphone", 2 ], 0031 [ 40, "iphone", 3 ], 0032 [ 57, "iphone", 1 ], 0033 [ 57, "iphone", 2 ], 0034 [ 60, "iphone", 2 ], 0035 [ 60, "iphone", 3 ], 0036 [ 29, "ipad", 1 ], 0037 [ 29, "ipad", 2 ], 0038 [ 40, "ipad", 1 ], 0039 [ 40, "ipad", 2 ], 0040 [ 50, "ipad", 1 ], 0041 [ 50, "ipad", 2 ], 0042 [ 72, "ipad", 1 ], 0043 [ 72, "ipad", 2 ], 0044 [ 76, "ipad", 1 ], 0045 [ 76, "ipad", 2 ], 0046 [ 83.5, "ipad", 2 ] 0047 ] 0048 0049 content = { 0050 "images": [], 0051 "info": { 0052 "version": 1, 0053 "author": "GCompris" 0054 } 0055 } 0056 0057 for image in images: 0058 size = image[0] 0059 idiom = image[1] 0060 scale = image[2] 0061 scalestr = str(scale) + 'x' 0062 filesizestr = str(int(size * scale)) + 'x' + str(int(size * scale)) 0063 sizestr = str(size) + 'x' + str(size) 0064 filename = "appicon-" + filesizestr + ".png" 0065 content['images'].append( 0066 { 0067 "size": sizestr, 0068 "idiom": idiom, 0069 "filename": filename, 0070 "scale": scalestr 0071 } 0072 ) 0073 0074 subprocess.call(["inkscape", image_source, 0075 "-e", outdir + '/' + filename, 0076 "-w", str(int(size * scale)), 0077 "-h", str(int(size * scale))]) 0078 0079 with open(outdir + '/Contents.json', 'w') as f: 0080 f.write(json.dumps(content, sort_keys=True, 0081 indent=4, separators=(',', ': ')))