File indexing completed on 2024-04-21 14:43:26
0001 #!/usr/bin/python3 0002 # 0003 # GCompris - createLaunchImage.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 from shutil import copyfile 0014 0015 0016 if len(sys.argv) < 3: 0017 print('Usage: createLaunchImage.py Images.xcassets/LaunchImage.launchimage ../../src/activities/menu/resource/background.svg') 0018 sys.exit(1) 0019 0020 outdir = sys.argv[1] 0021 image_source = sys.argv[2] 0022 0023 # Should be extracted from the source image 0024 source_width = 1052 0025 source_height = 610 0026 0027 try: 0028 os.makedirs(outdir) 0029 except: 0030 pass 0031 0032 images = [ 0033 { 0034 "extent" : "full-screen", 0035 "idiom" : "iphone", 0036 "subtype" : "736h", 0037 "width": 1242, "height": 2208, 0038 "minimum-system-version" : "8.0", 0039 "orientation" : "portrait", 0040 "scale" : "3x" 0041 }, 0042 { 0043 "extent" : "full-screen", 0044 "idiom" : "iphone", 0045 "subtype" : "736h", 0046 "width": 2208, "height": 1242, 0047 "minimum-system-version" : "8.0", 0048 "orientation" : "landscape", 0049 "scale" : "3x" 0050 }, 0051 { 0052 "extent" : "full-screen", 0053 "idiom" : "iphone", 0054 "subtype" : "667h", 0055 "width": 750, "height": 1334, 0056 "minimum-system-version" : "8.0", 0057 "orientation" : "portrait", 0058 "scale" : "2x" 0059 }, 0060 { 0061 "orientation" : "portrait", 0062 "idiom" : "iphone", 0063 "width": 640, "height": 960, 0064 "extent" : "full-screen", 0065 "minimum-system-version" : "7.0", 0066 "scale" : "2x" 0067 }, 0068 { 0069 "extent" : "full-screen", 0070 "idiom" : "iphone", 0071 "subtype" : "retina4", 0072 "width": 640, "height": 1136, 0073 "minimum-system-version" : "7.0", 0074 "orientation" : "portrait", 0075 "scale" : "2x" 0076 }, 0077 { 0078 "orientation" : "portrait", 0079 "idiom" : "ipad", 0080 "width": 768, "height": 1024, 0081 "extent" : "full-screen", 0082 "minimum-system-version" : "7.0", 0083 "scale" : "1x" 0084 }, 0085 { 0086 "orientation" : "landscape", 0087 "idiom" : "ipad", 0088 "width": 1024, "height": 768, 0089 "extent" : "full-screen", 0090 "minimum-system-version" : "7.0", 0091 "scale" : "1x" 0092 }, 0093 { 0094 "orientation" : "portrait", 0095 "idiom" : "ipad", 0096 "width": 1536, "height": 2048, 0097 "extent" : "full-screen", 0098 "minimum-system-version" : "7.0", 0099 "scale" : "2x" 0100 }, 0101 { 0102 "orientation" : "landscape", 0103 "idiom" : "ipad", 0104 "width": 2048, "height": 1536, 0105 "extent" : "full-screen", 0106 "minimum-system-version" : "7.0", 0107 "scale" : "2x" 0108 }, 0109 { 0110 "orientation" : "portrait", 0111 "idiom" : "iphone", 0112 "width": 320, "height": 480, 0113 "extent" : "full-screen", 0114 "scale" : "1x" 0115 }, 0116 { 0117 "orientation" : "portrait", 0118 "idiom" : "iphone", 0119 "width": 640, "height": 960, 0120 "extent" : "full-screen", 0121 "scale" : "2x" 0122 }, 0123 { 0124 "orientation" : "portrait", 0125 "idiom" : "iphone", 0126 "width": 640, "height": 1136, 0127 "extent" : "full-screen", 0128 "subtype" : "retina4", 0129 "scale" : "2x" 0130 }, 0131 { 0132 "orientation" : "portrait", 0133 "idiom" : "ipad", 0134 "width": 768, "height": 1004, 0135 "extent" : "to-status-bar", 0136 "scale" : "1x" 0137 }, 0138 { 0139 "orientation" : "portrait", 0140 "idiom" : "ipad", 0141 "width": 768, "height": 1024, 0142 "extent" : "full-screen", 0143 "scale" : "1x" 0144 }, 0145 { 0146 "orientation" : "landscape", 0147 "idiom" : "ipad", 0148 "width": 1024, "height": 748, 0149 "extent" : "to-status-bar", 0150 "scale" : "1x" 0151 }, 0152 { 0153 "orientation" : "landscape", 0154 "idiom" : "ipad", 0155 "width": 1024, "height": 768, 0156 "extent" : "full-screen", 0157 "scale" : "1x" 0158 }, 0159 { 0160 "orientation" : "portrait", 0161 "idiom" : "ipad", 0162 "width": 1536, "height": 2008, 0163 "extent" : "to-status-bar", 0164 "scale" : "2x" 0165 }, 0166 { 0167 "orientation" : "portrait", 0168 "idiom" : "ipad", 0169 "width": 1536, "height": 2048, 0170 "extent" : "full-screen", 0171 "scale" : "2x" 0172 }, 0173 { 0174 "orientation" : "landscape", 0175 "idiom" : "ipad", 0176 "width": 2048, "height": 1496, 0177 "extent" : "to-status-bar", 0178 "scale" : "2x" 0179 }, 0180 { 0181 "orientation" : "landscape", 0182 "idiom" : "ipad", 0183 "width": 2048, "height": 1536, 0184 "extent" : "full-screen", 0185 "scale" : "2x" 0186 } 0187 ] 0188 0189 content = { 0190 "images": [], 0191 "info": { 0192 "version": 1, 0193 "author": "GCompris" 0194 } 0195 } 0196 0197 for image in images: 0198 print(image) 0199 width = int(image['width']) 0200 height = int(image['height']) 0201 sizestr = str(width) + 'x' + str(height) 0202 image['filename'] = "appicon-" + sizestr + ".png" 0203 content['images'].append(image) 0204 0205 # Calc the cropping area 0206 rw = source_width / width 0207 rh = source_height / height 0208 r = min(rw, rh) 0209 width_final = int(width * r) 0210 height_final = int(height * r) 0211 0212 area_x = int((source_width - width_final) / 2) 0213 area_y = int((source_height - height_final) / 2) 0214 area = str(area_x) + ':' + \ 0215 str(area_y) + ':' + \ 0216 str(area_x + width_final) + ':' + \ 0217 str(area_y + height_final) 0218 0219 subprocess.call(["inkscape", image_source, 0220 "-e", outdir + '/' + image['filename'], 0221 "-a", area, 0222 "-w", str(width), 0223 "-h", str(height)]) 0224 0225 with open(outdir + '/Contents.json', 'w') as f: 0226 f.write(json.dumps(content, sort_keys=True, 0227 indent=4, separators=(',', ': '))) 0228 0229 0230 # Create the Default-658h.png 0231 copyfile(outdir + '/appicon-640x1136.png', outdir + '/../Default-568h@2x.png')