CHKim

iOS launch-image resize

May 27th, 2017
404
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. # this script need pillow library
  2. # this script tested on python 2.7.13
  3.  
  4. # install pillow libary by pip
  5. # * pip install Pillow
  6. # usage
  7. # * iosLaunchImageResize.py <sourceimage-filename>
  8. # source image must have square (more than 2048 if possible)
  9.  
  10. launchImageSize = {
  11.     "1x" : (320, 480),
  12.     "2x" : (640, 960),
  13.     "4" : (640, 1136),      # Retina 4
  14.     "5.5" : (1242, 2208),   # Retina HD 5.5
  15.     "4.7" : (750, 1334),    # Retina HD 4.7
  16.     "5.5L" : (2208, 1242),  # Retina HD 5.5 Landscape
  17.     "iPad1x" : (768, 1024),
  18.     "iPad2x" : (1536, 2048),
  19.     "iPad1xL" : (1024, 768), # Landscape
  20.     "iPad2xL" : (2048, 1536),# Landscape
  21. }
  22.  
  23. import os
  24. import sys
  25.  
  26. from PIL import Image
  27.  
  28. def saveResizeImage(image, outfilename, w, h):  
  29.     rs = w if w > h else h
  30.     rsimage = image.resize((rs, rs), Image.BICUBIC)
  31.  
  32.     x = (rs - w)/2
  33.     y = (rs - h)/2
  34.  
  35.     box = (x, y, x + w, y + h)
  36.     # print(box, rs)
  37.  
  38.     region = rsimage.crop(box)
  39.     region.save(outfilename)
  40.     del region
  41.     return
  42.  
  43. def imageResizeMain(filename):
  44.     im = Image.open(filename)
  45.     for k in launchImageSize:
  46.         s = launchImageSize[k]
  47.         ofn = "{0}_{1}.png".format(filename.split('.')[0], k)
  48.         saveResizeImage(im, ofn, s[0], s[1])
  49.  
  50. if __name__ == "__main__":
  51.     args = len(sys.argv)
  52.     if args == 2:
  53.         imageResizeMain(sys.argv[1])
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment