Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this script need pillow library
- # this script tested on python 2.7.13
- # install pillow libary by pip
- # * pip install Pillow
- # usage
- # * iosLaunchImageResize.py <sourceimage-filename>
- # source image must have square (more than 2048 if possible)
- launchImageSize = {
- "1x" : (320, 480),
- "2x" : (640, 960),
- "4" : (640, 1136), # Retina 4
- "5.5" : (1242, 2208), # Retina HD 5.5
- "4.7" : (750, 1334), # Retina HD 4.7
- "5.5L" : (2208, 1242), # Retina HD 5.5 Landscape
- "iPad1x" : (768, 1024),
- "iPad2x" : (1536, 2048),
- "iPad1xL" : (1024, 768), # Landscape
- "iPad2xL" : (2048, 1536),# Landscape
- }
- import os
- import sys
- from PIL import Image
- def saveResizeImage(image, outfilename, w, h):
- rs = w if w > h else h
- rsimage = image.resize((rs, rs), Image.BICUBIC)
- x = (rs - w)/2
- y = (rs - h)/2
- box = (x, y, x + w, y + h)
- # print(box, rs)
- region = rsimage.crop(box)
- region.save(outfilename)
- del region
- return
- def imageResizeMain(filename):
- im = Image.open(filename)
- for k in launchImageSize:
- s = launchImageSize[k]
- ofn = "{0}_{1}.png".format(filename.split('.')[0], k)
- saveResizeImage(im, ofn, s[0], s[1])
- if __name__ == "__main__":
- args = len(sys.argv)
- if args == 2:
- imageResizeMain(sys.argv[1])
Advertisement