I created an icon converter script. I could make it a full GUI program, but I developed this to automate a rather annoying task. I used to resize all the images with Gimp, and that could take the better part of a day to complete. How many images does Apple need to have assets completed? The answer is 38… As of right now that is. All different sizes, so I decided to make a script.
I know nothing about images, other than if you make a small image bigger it will look stretched, so I decided big to small is the best way to go.
Task to complete:
- Take larger image, and create 38 organized icons based off of that image
The instructions for the app is simple.
- Place image in root folder. 1024×1024 is suggested.
- run script using terminal “python batchicon.py”. Make sure you run it from the root folder, and not through a path. 3 folders will be created with all required icon for iOS.
Ok, so lets get to the script!
Step 1: You need an image. You can take this one for an example if you want to run the script.
Step 2: You need the script! But I will talk a bit about the script because lots of it was made for my connivence.
I used PIL for the image manipulation, and my strategy was to just take the biggest image and break it down 1 at a time. Is there a better way to do this? Probably, but it gets the job done instantly, and I haven’t had any issues with it.
Come to think of it, I have never tried this one Windows, so I am unsure if it will work or not.
I poll the entire folder for images, so please only put 1 image with the script location.
#!/usr/bin/env python
import PIL
from PIL import Image
import os, sys
def resizeImagePhone(infile,size=0,name=""):
#print(""+ name +" ")
outfile = name
extension = os.path.splitext(infile)[1]
if (cmp(extension, ".png")):
return
if infile != outfile:
try :
im = Image.open(infile)
im.thumbnail((size,size), Image.ANTIALIAS)
im.save("iPhone/"+outfile+extension,"PNG")
except IOError:
print "cannot reduce image for ", infile
def resizeImagePad(infile,size=0,name=""):
#print(""+ name +" ")
outfile = name
extension = os.path.splitext(infile)[1]
if (cmp(extension, ".png")):
return
if infile != outfile:
try :
im = Image.open(infile)
im.thumbnail((size,size), Image.ANTIALIAS)
im.save("iPad/"+outfile+extension,"PNG")
except IOError:
print "cannot reduce image for ", infile
def resizeMisc(infile,size=0,name=""):
#print(""+ name +" ")
outfile = name
extension = os.path.splitext(infile)[1]
if (cmp(extension, ".png")):
return
if infile != outfile:
try :
im = Image.open(infile)
im.thumbnail((size,size), Image.ANTIALIAS)
im.save("misc/"+outfile+extension,"PNG")
except IOError:
print "cannot reduce image for ", infile
if __name__=="__main__":
dir = os.getcwd()
if not os.path.exists(os.path.join(dir,"iPhone")):
os.mkdir("iPhone")
if not os.path.exists(os.path.join(dir,"iPad")):
os.mkdir("iPad")
if not os.path.exists(os.path.join(dir,"misc")):
os.mkdir("misc")
for file in os.listdir(dir):
print("Checking: " + str(file))
#Table 1
resizeImagePhone(file,120,"Icon-60@2x")
resizeImagePhone(file,180,"Icon-60@3x")
resizeImagePhone(file,76,"Icon-76")
resizeImagePhone(file,152,"Icon-76@2x")
resizeImagePhone(file,167,"Icon-82.5@2x")
resizeImagePhone(file,40,"Icon-Small-40")
resizeImagePhone(file,80,"Icon-Small-40@2x")
resizeImagePhone(file,120,"Icon-Small-40@3x")
resizeImagePhone(file,29,"Icon-Small")
resizeImagePhone(file,58,"Icon-Small@2x")
resizeImagePhone(file,87,"Icon-Small@3x")
#Table 2
resizeImagePhone(file,57,"Icon")
resizeImagePhone(file,114,"Icon@2x")
resizeImagePhone(file,72,"Icon-72")
resizeImagePhone(file,144,"Icon-72@2x")
resizeImagePhone(file,29,"Icon-Small")
resizeImagePhone(file,58,"Icon-Small@2x")
resizeImagePhone(file,50,"Icon-Small-50")
resizeImagePhone(file,100,"Icon-Small-50@2x")
#Table 3
resizeImagePad(file,512,"iTunesArtwork")
resizeImagePad(file,1024,"iTunesArtwork@2x")
resizeImagePad(file,76,"Icon-76")
resizeImagePad(file,152,"Icon-76@2x")
resizeImagePad(file,167,"Icon-83.5@2x")
resizeImagePad(file,40,"Icon-Small-40")
resizeImagePad(file,80,"Icon-Small-40@2x")
resizeImagePad(file,29,"Icon-Small")
resizeImagePad(file,58,"Icon-Small@2x")
#Table 4
resizeImagePad(file,72,"Icon-72")
resizeImagePad(file,144,"Icon-72@2x")
resizeImagePad(file,50,"Icon-Small-50")
resizeImagePad(file,100,"Icon-Small-50@2x")
#Misc Icons (Notifications, Settings, etc)
resizeMisc(file,40,"iPhoneNotification-2x")
resizeMisc(file,60,"iPhoneNotification-3x")
resizeMisc(file,20,"iPadNotification-1x")
resizeMisc(file,40,"iPadNotification-2x")
resizeMisc(file,29,"iPadSettings-1x")
resizeMisc(file,58,"iPadSettings-2x")
resizeMisc(file,40,"iPadSpotlight-1x")
resizeMisc(file,80,"iPadSpotlight-2x")
print("Ok, all done!!")
After your script runs you should have a directly that looks like this.