Technology

iOS icon size generator

One of the things you run into while developing iOS applications is that you need several different icon sizes for the various devices.  For an iOS 8 iPhone application, you need at least 4 different sizes: 58pt, 80pt, 120pt, and 180pt.  Not to mention the main icon size for the app store.  If you develop a Universal App for the iPad there's even more! I'm sure there are tons of things people use to do this but I thought I'd throw my own solution in the mix as well. I use ImageMagick with a python script I wrote.  I like it because its quick and easy.  Plus, if you are developing in Ruby on Rails and need something like CarrierWave to upload images, you'll already have ImageMagick installed. Here's how it works:

1.  Install ImageMagick

brew install imagemagick

2.  Use my python script

#!/usr/bin/env python
# place the icon in the same directory as this script and run it. 
# e.g: ./makeicons.py icon\@1024.png

from subprocess import call
import sys 

sizes = [29, 40, 60, 76 ]

if len(sys.argv) < 2:
  print "please enter a file name to process"
  exit()

for s in sizes:
  for p in range(1,3):
    ss = p * s 
    g = "%dx%d" % (ss, ss) 
    iconName = "icon@%d.png" % ss
    print "Making icon %s" % iconName
    call(["convert", sys.argv[1], "-resize", g, iconName])

g = "180x180"
iconName = "icon@180.png"
print "Making icon %s" % iconName
call(["convert", sys.argv[1], "-resize", g, iconName])

 Run the Python Script

With your original sized icon in the same directory as this script run the script.  Here's my output example.  The file I put in the directory is called icon2@1024.png.
$ ./makeicons.py icon2\@1024.png 
Making icon icon@29.png
Making icon icon@58.png
Making icon icon@40.png
Making icon icon@80.png
Making icon icon@60.png
Making icon icon@120.png
Making icon icon@76.png
Making icon icon@152.png
Making icon icon@180.png
As you can see, it generated all the image sizes you would need for your asset images.