Skip to content

Instantly share code, notes, and snippets.

@ayushgoel
Last active August 29, 2015 14:20
Show Gist options
  • Save ayushgoel/dd403e658162f8466532 to your computer and use it in GitHub Desktop.
Save ayushgoel/dd403e658162f8466532 to your computer and use it in GitHub Desktop.
Convert one image to all required sizes for iOS icons and artwork with understandable names
#!/usr/bin/env python3
import PIL.Image as Image
import sys
extension = ".png"
def saveImage(image, imageName):
image.save(imageName + extension)
IconNamePrefix = "Icon"
IconSizes = [(58, 58), (80, 80), (87, 87), (120, 120), (180, 180)];
def convertImageToIcons(image):
for size in IconSizes:
convertedImage = image.resize(size, Image.ANTIALIAS)
saveImage(convertedImage, IconNamePrefix + str(size[0]))
ArtworkNamePrefix = "iTunesArtwork"
ArtworkSizes = [(512, 512), (1024, 1024)];
def convertImageToArtwork(image):
for size in ArtworkSizes:
artwork = image.resize(size, Image.ANTIALIAS)
artworkSuffix = '@2x' if size[0] > 512 else '' #I hate this line
saveImage(artwork, ArtworkNamePrefix + artworkSuffix)
if __name__ == '__main__':
imageName = sys.argv[1]
image = Image.open(imageName)
convertImageToIcons(image)
convertImageToArtwork(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment