Generating multiple icon sizes

I was starting to look around in Xcode 5 and noticed that creating an AppIcon in image assets now has space for twenty items (that’s not including the eight for the watch).  This comprises seventeen different sizes which map to 29, 40, 50, 57, 58, 60, 72, 76, 80, 87, 100, 114, 120, 144, 152, 167 and 180 pixels.  That’s a lot of ‘Save for web…’ commands in Photoshop.

A quicker way is to use the Mac’s built-in sips (scriptable image processing system) command.  Generate your icon at a large size (1024 pixels and above) and call it appIcon.png.  Then go into that folder in Terminal and run the following commands:

cp appIcon.png iPhoneSpotlight_29pt_x1.png
cp appIcon.png iPhoneSpotlight_29pt_x2.png
cp appIcon.png iPhoneSpotlight_29pt_x3.png
cp appIcon.png iPhoneSpotlight_40pt_x2.png
cp appIcon.png iPhoneSpotlight_40pt_x3.png
cp appIcon.png iPhoneApp_57pt_x1.png
cp appIcon.png iPhoneApp_57pt_x2.png
cp appIcon.png iPhoneApp_60pt_x2.png
cp appIcon.png iPhoneApp_60pt_x3.png
cp appIcon.png iPadSettings_29pt_x1.png
cp appIcon.png iPadSettings_29pt_x2.png
cp appIcon.png iPadSpotlight_40pt_x1.png
cp appIcon.png iPadSpotlight_40pt_x2.png
cp appIcon.png iPadSpotlight_50pt_x1.png
cp appIcon.png iPadSpotlight_50pt_x2.png
cp appIcon.png iPadApp_72pt_x1.png
cp appIcon.png iPadApp_72pt_x2.png
cp appIcon.png iPadApp_76pt_x1.png
cp appIcon.png iPadApp_76pt_x2.png
cp appIcon.png iPadProApp_83-5pt_x2.png

sips -Z 29 iPhoneSpotlight_29pt_x1.png
sips -Z 58 iPhoneSpotlight_29pt_x2.png
sips -Z 87 iPhoneSpotlight_29pt_x3.png
sips -Z 80 iPhoneSpotlight_40pt_x2.png
sips -Z 120 iPhoneSpotlight_40pt_x3.png
sips -Z 57 iPhoneApp_57pt_x1.png
sips -Z 114 iPhoneApp_57pt_x2.png
sips -Z 120 iPhoneApp_60pt_x2.png
sips -Z 180 iPhoneApp_60pt_x3.png
sips -Z 29 iPadSettings_29pt_x1.png
sips -Z 58 iPadSettings_29pt_x2.png
sips -Z 40 iPadSpotlight_40pt_x1.png
sips -Z 80 iPadSpotlight_40pt_x2.png
sips -Z 50 iPadSpotlight_50pt_x1.png
sips -Z 100 iPadSpotlight_50pt_x2.png
sips -Z 72 iPadApp_72pt_x1.png
sips -Z 144 iPadApp_72pt_x2.png
sips -Z 76 iPadApp_76pt_x1.png
sips -Z 152 iPadApp_76pt_x2.png
sips -Z 167 iPadProApp_83-5pt_x2.png

It will copy the large image file to all the correctly named targets and then scale them to the required sizes.  Once they have been added into Xcode as image assets then updating them is simply a matter of generating the files again and copying over the existing ones in the Finder.