Skip to content

Instantly share code, notes, and snippets.

@anthonycastelli
Created February 10, 2015 21:01
Show Gist options
  • Save anthonycastelli/1e614bf0708821cf5ad0 to your computer and use it in GitHub Desktop.
Save anthonycastelli/1e614bf0708821cf5ad0 to your computer and use it in GitHub Desktop.
iOS 8 Icons
import os
import sys
import numpy
from PIL import Image
if len(sys.argv) < 3:
print('You must specifiy an image and an output folder')
print('i.e. "resizer.py image.png output_folder_name')
sys.exit(1)
# iOS 8 iPhone icon sizes
iphone = {
58: '[email protected]',
87: '[email protected]',
80: '[email protected]',
120: '[email protected]',
120: '[email protected]',
180: '[email protected]'
}
# iOS 8 iPad icon sizes
ipad = {
29: 'icon_ipad_small.png',
58: '[email protected]',
40: 'icon_ipad_spotlight.png',
80: '[email protected]',
76: 'icon_ipad.png',
152: '[email protected]'
}
imageFile = sys.argv[1]
outputFolder = sys.argv[2]
# Define our resizing method
def resizeImage(image, size, output):
img = Image.open(image)
premult = numpy.fromstring(img.tostring(), dtype=numpy.uint8)
alphaLayer = premult[3::4] / 255.0
premult[::4] *= alphaLayer
premult[1::4] *= alphaLayer
premult[2::4] *= alphaLayer
img = Image.fromstring("RGBA", img.size, premult.tostring())
img.resize((size, size), Image.ANTIALIAS).save(output)
# Check and see if the folder already exists
if not os.path.isdir(outputFolder):
os.mkdir(outputFolder)
# Change our current working directory to our output folder
os.chdir(outputFolder)
print('### Converting iPhone Icons ###')
for size in iphone.keys():
print(' Creating %s icon' % iphone[size])
resizeImage(imageFile, size, iphone[size])
print('### Finished Creating iPhone Icons ###')
print('')
print('### Converting iPad Icons ###')
for size in ipad.keys():
print(' Creating %s icon' % ipad[size])
resizeImage(imageFile, size, ipad[size])
print('### Finished Creating iPhone Icons ###')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment