Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Python3
- """Creates resized copies of the user's selected app icon to all sizes that iOS 8 requires
- and renames those copies to the names iOS 8 requires."""
- import os
- import sys
- import shutil
- from typing import List, Tuple
- from tkinter import Tk
- from tkinter.filedialog import askopenfilename
- from PIL import Image
- # iOS 8 required and recommended app icon sizes
- icon_sizes = [29, 58, 87, 40, 80, 60, 120, 180, 76, 152, 512, 1024]
- # Corresponding names
- icon_names = ["Icon-Small.png",
- "Icon-Small@2x.png",
- "Icon-Small@3x.png",
- "Icon-Small-40.png",
- "Icon-Small-40@2x.png",
- "Icon-60.png",
- "Icon-60@2x.png",
- "Icon-60@3x.png",
- "Icon-76.png",
- "Icon-76@2x.png",
- "iTunesArtwork.png",
- "iTunesArtwork@2x.png",
- ]
- # folder name in which copies are stored
- destination = "output"
- def open_img():
- """Opens file dialog and returns image selected"""
- Tk().withdraw()
- filename = askopenfilename()
- try:
- return Image.open(filename)
- except Exception as e:
- print("No file opened: {}".format(e))
- sys.exit(1)
- def resize(img, size: int):
- """Resizes given square image to given side dimension"""
- return img.resize((size, size), Image.ANTIALIAS)
- def save_imgs(names_and_images: List[Tuple[str, type]]):
- """Saves all created images to destination folder"""
- for name, img in names_and_images:
- img.save(os.path.join(destination, name))
- if __name__ == "__main__":
- original = open_img()
- names_and_sizes = list(zip(icon_names, icon_sizes))
- names_and_images = [(name, resize(original, size))
- for name, size in names_and_sizes]
- if os.path.exists(destination):
- shutil.rmtree(destination, ignore_errors=True)
- os.mkdir(destination)
- save_imgs(names_and_images)
Add Comment
Please, Sign In to add comment