Brief introduction
The two days after the update Xcode8 found that Xcode to the icon requirements have changed, used before a small application of "Iconkit" has not caught up with the rhythm, can not meet the Xcode8 requirements.
So I thought of using Python to make my own script to generate an icon.
In fact, this script is written very early, now in order to adapt to iOS10, on the revised and perfected, and put to the GitHub.
You can look at the effect chart:
Code:
#encoding =utf-8 #by Lights #create date 2016/5/22 #update 2016/9/21 #support iOS #site www.winterfeel.com import os im Port sys from PIL import Image iossizes = [' 20@1x ', ' 20@2x ', ' 20@3x ', ' 29@1x ', ' 29@2x ', ' 29@3x ', ' 40@1x ', ' 40@2x ', ' 40@3x ', ' 60 @2x ', ' 60@3x ', ' 60@3x ', ' 76@1x ', ' 76@2x ', ' 167@1x '] androidsizes = [32,48,72,96,144,192] androidnames = [' ldpi ', ' mdpi ', ' Hdpi ', ' xhdpi ', ' xxhdpi ', ' xxxhdpi '] Sizesios = [(640,960), (640, 1136), (750, 1334), (1242, 2208), (1536, 2048), (2048, 2732) ] Foldersios = [' iphone4s ', ' iPhone5 ', ' iPhone6 ', ' iphone6plus ', ' iPad ', ' ipadlarge '] sizesandroid = [(480,800), (720,1280 ), (1080,1920)] foldersandroid = [' 480x800 ', ' 720x1280 ', ' 1080x1920 '] def processicon (filename,platform): Icon = Image.open (filename). CONVERT ("RGBA") if icon.size[0]!= icon.size[1]: print ' icon file must be a rectangle! ' return if PLA Tform = = ' Android ': #安卓圆角 mask = image.open (' mask.png ') R,g,b,a = Mask.split () icon.putalpha (a) if not os.path.isdir (' Andr Oidicon '): Os.mkdir (' Androidicon ') index = 0 for size inAndroidsizes:im = Icon.resize (size,size), image.bilinear) im.save (' androidicon/icon-' + androidnames[index]+ '. png ') index = index + 1 else:if not Os.path.isdir (' Iosicon '): Os.mkdir (' Iosicon ') for the size in iossizes:originalsize = Int (size . Split (' @ ') [0]) #原始尺寸 multiply = Int (size.split (' @ ') [1][0:1]) #倍数 im = Icon.resize (originalsize*multiply,originalsize *multiply), Image.bilinear) im.save (' Iosicon/icon ' +size+ '. png ') print ' congratulations! It\ ' s All done! ' Def walk_dir (dir,platform): Files = Os.listdir (dir) for name in Files:if name.split ('. ') [-1] = = ' jpg ' or name.split ('. ') [-1] = = ' png ': #处理jpg和png produceimage (name,platform) print ' congratulations!
It\ ' s All done! ' Def produceimage (filename,platform): print ' processing: ' + filename img = image.open (filename) index = 0
Sizes = Sizesios Folders = Foldersios If platform = ' Android ': #默认ios, if it is an android sizes = sizesandroid folders = foldersandroid For size in sizes:if not Os.path.isdir (Folders[index]): Os.mkdir (Folders[index]) if img.size[0] >IMG.SIZE[1]: #如果是横屏, exchange coordinates im = Img.resize ((size[1],size[0), image.bilinear) im.save (folders[index]+ '/' +filename) Else : im = Img.resize (size,image.bilinear) im.save (folders[index]+ '/' +filename) index = index + 1 action = sys.argv[1] #action:
Icon or screenshot if action = = ' screenshot ': platform = sys.argv[2] #platform If platform = ' iOS ': Walk_dir ('./', ' iOS ') elif platform = = ' Android ': Walk_dir ('./', ' Android ') Else:print ' hey,platform can only be ' iOS ' or ' Android '! ' Elif acti on = = ' Icon ': filename = sys.argv[2] #image filename platform = sys.argv[3] #platform if not os.path.exists (filename): Print ' Hey,file not found! ' else:if platform = = ' iOS ': processicon (filename, ' iOS ') elif platform = ' Android ': Processicon (fil ename, ' Android ' Else:print ' Hey,platform can only be ' iOS ' or ' Android '! ' Else:print ' hey,action can is ' icon ' or "Screenshot"! '
Scripting environment Requirements
Python 2.7
PiL or Pillow
The author of the test, perhaps the author too, tried a variety of methods to install PIL is always wrong, and finally used the pillow, the effect of the same.
How to use a script
At the command line of Windows or at the end of the Mac, enter:
Python tool.py [action] [filename] [platform]
Action:icon or screenshot.
FileName: Icon filename, screenshot does not require file name, automatic traversal
Platform:ios or Android
Give some examples:
Create iOS icon: Python tool.py icon icon.jpg iOS
Build android Icon: Python tool.py icon icon.jpg android
To generate a screenshot of iOS: Python tool.py screenshot ios
Build Android Screenshots: Python tool.py screenshot android
Pay attention.
The creation of an Android fillet icon requires a PNG to be cropped, the dimensions 512x512,70 rounded, and the GitHub is already attached.
All JPG and PNG files are automatically traversed when the screenshot is generated, and the screen is automatically identified.
Conclusion
If you find it useful, welcome to star in GitHub, also welcome the improvement, the code is easy to understand and add notes.
GitHub Address
The above is a small set to introduce you to teach you to use Python script quickly for iOS10 to generate icons and screenshots of all the narration, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!