Advertisement
cptnoblivious

iOS Icon Resize Simple Script (Python)

Jan 28th, 2022
1,409
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import os.path
  5. from PIL import Image #windows
  6. # import Image #MacOS
  7. import string
  8.  
  9. ###USAGE: python ios_icon_resize.py
  10.  
  11. ### Script by Firecracker Software
  12. ### http://www.firecrackersw.com
  13. ### Use freely; no attribution required.
  14.  
  15. ### This script relies on PIL, the Python Image Library.
  16. ### It will not work with the newer "Pillow" image library.
  17.  
  18. ### Place this script in a directory containing your iTunesArtwork@2x
  19. ### asset (1024x1024 px) and run from command line.
  20.  
  21. EXPORT_QUALITY=100
  22.  
  23. def main():
  24.  
  25.     #Import the image into an image object.
  26.     im = Image.open("iTunesArtwork@2x.png")
  27.     width = im.size[0]
  28.     height = im.size[1]
  29.  
  30.     #Resize for all known icon sizes.
  31.     resize(im, "Icon-20", 20, 20)
  32.     resize(im, "Icon-20@2x", 40, 40)
  33.     resize(im, "Icon-20@3x", 60, 60)
  34.    
  35.     resize(im, "Icon-29", 29, 29)
  36.     resize(im, "Icon-29@2x", 58, 58)
  37.     resize(im, "Icon-29@3x", 87, 87)
  38.    
  39.     resize(im, "Icon-40", 40, 40)
  40.     resize(im, "Icon-40@2x", 80, 80)
  41.     resize(im, "Icon-40@3x", 120, 120)
  42.    
  43.     resize(im, "Icon-57", 57, 57)
  44.     resize(im, "Icon-57@2x", 114, 114)
  45.    
  46.     resize(im, "Icon-60@2x", 120, 120)
  47.     resize(im, "Icon-60@3x", 180, 180)
  48.    
  49.     resize(im, "Icon-50", 50, 50)
  50.     resize(im, "Icon-50@2x", 100, 100)
  51.    
  52.     resize(im, "Icon-72", 72, 72)
  53.     resize(im, "Icon-72@2x", 144, 144)
  54.    
  55.     resize(im, "Icon-76", 76, 76)
  56.     resize(im, "Icon-76@2x", 152, 152)
  57.    
  58.     resize(im, "Icon-83.5@2x", 167, 167)
  59.    
  60.     resize(im, "iTunesArtwork", 512, 512)
  61.     #With iTunesArtwork@2x taken as granted.
  62.  
  63. def resize(im, name, width, height):
  64.     #Resize the image object to the target size.
  65.     im = im.resize((height, height), Image.ANTIALIAS)
  66.    
  67.     #Perform cropping pass.  Really only useful for iOS 6 and below.
  68.     left = (height - width)/2       #Crops from center of icon.
  69.     top = 0
  70.     right = (height + width)/2
  71.     bottom = height
  72.     finalcrop = im.crop((left, top, right, bottom))
  73.    
  74.     #Save the final result.
  75.     finalcrop.save(str(name) + ".png", quality=EXPORT_QUALITY)
  76.    
  77. if __name__ == "__main__":
  78.     main()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement