Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create iOS application icons from one PDF file. Requires ImageMagick.
#!/bin/sh
#
# Iconizer shell script by Steve Richey (srichey@floatlearning.com)
#
# This is a simple tool to generate all necessary app icon sizes and the JSON file for an *EXISTING* Xcode project from one file.
# To use: specify the path to your vector graphic (PDF format) and the path to your Xcode folder containing Images.xcassets
# Example: sh iconizer.sh MyVectorGraphic.pdf MyXcodeProject
#
# Requires ImageMagick: http://www.imagemagick.org/
if [ $# -ne 2 ]
then
echo "\nUsage: sh iconizer.sh file.pdf FolderName\n"
elif [ ! -e "$1" ]
then
echo "Did not find file $1, expected path to a vector image file.\n"
elif [ ${1: -4} != ".pdf" ]
then
echo "File $1 is not a vector image file! Expected PDF file.\n"
elif [ ! -d "./$2/Images.xcassets/AppIcon.appiconset/" ]
then
echo "Did not find Xcode folder $2, expected folder which contains Images.xcassets/AppIcon.appiconset/ \n"
else
echo "Creating icons from $1 into $2/Images.xcassets/AppIcon.appiconset/..."
for i in 16 29 32 40 50 57 58 64 72 76 80 87 100 114 120 128 144 152 180 256 512 1024
do
echo "Creating $i px icon"
convert -density 400 $1 -scale $ix$i ./$2/Images.xcassets/AppIcon.appiconset/appicon_$i.png
done
echo "Created app icon files, writing Contents.json file..."
echo '{"images":[\n{\n"size":"29x29",\n"idiom":"iphone",\n"filename":"appicon_29.png",\n"scale":"1x"\n},\n{\n"size":"29x29",\n"idiom":"iphone",\n"filename":"appicon_58.png",\n"scale":"2x"\n},\n{\n"size":"29x29",\n"idiom":"iphone",\n"filename":"appicon_87.png",\n"scale":"3x"\n},\n{\n"size":"40x40",\n"idiom":"iphone",\n"filename":"appicon_80.png",\n"scale":"2x"\n},\n{\n"size":"40x40",\n"idiom":"iphone",\n"filename":"appicon_120.png",\n"scale":"3x"\n},\n{\n"size":"57x57",\n"idiom":"iphone",\n"filename":"appicon_57.png",\n"scale":"1x"\n},\n{\n"size":"57x57",\n"idiom":"iphone",\n"filename":"appicon_114.png",\n"scale":"2x"\n},\n{\n"size":"60x60",\n"idiom":"iphone",\n"filename":"appicon_120.png",\n"scale":"2x"\n},\n{\n"size":"60x60",\n"idiom":"iphone",\n"filename":"appicon_180.png",\n"scale":"3x"\n},\n{\n"size":"29x29",\n"idiom":"ipad",\n"filename":"appicon_29.png",\n"scale":"1x"\n},\n{\n"size":"29x29",\n"idiom":"ipad",\n"filename":"appicon_58.png",\n"scale":"2x"\n},\n{\n"size":"40x40",\n"idiom":"ipad",\n"filename":"appicon_40.png",\n"scale":"1x"\n},\n{\n"size":"40x40",\n"idiom":"ipad",\n"filename":"appicon_80.png",\n"scale":"2x"\n},\n{\n"size":"50x50",\n"idiom":"ipad",\n"filename":"appicon_50.png",\n"scale":"1x"\n},\n{\n"size":"50x50",\n"idiom":"ipad",\n"filename":"appicon_100.png",\n"scale":"2x"\n},\n{\n"size":"72x72",\n"idiom":"ipad",\n"filename":"appicon_72.png",\n"scale":"1x"\n},\n{\n"size":"72x72",\n"idiom":"ipad",\n"filename":"appicon_144.png",\n"scale":"2x"\n},\n{\n"size":"76x76",\n"idiom":"ipad",\n"filename":"appicon_76.png",\n"scale":"1x"\n},\n{\n"size":"76x76",\n"idiom":"ipad",\n"filename":"appicon_152.png",\n"scale":"2x"\n},\n{\n"size":"120x120",\n"idiom":"car",\n"filename":"appicon_120.png",\n"scale":"1x"\n},\n{\n"size":"16x16",\n"idiom":"mac",\n"filename":"appicon_16.png",\n"scale":"1x"\n},\n{\n"size":"16x16",\n"idiom":"mac",\n"filename":"appicon_32.png",\n"scale":"2x"\n},\n{\n"size":"32x32",\n"idiom":"mac",\n"filename":"appicon_32.png",\n"scale":"1x"\n},\n{\n"size":"32x32",\n"idiom":"mac",\n"filename":"appicon_64.png",\n"scale":"2x"\n},\n{\n"size":"128x128",\n"idiom":"mac",\n"filename":"appicon_128.png",\n"scale":"1x"\n},\n{\n"size":"128x128",\n"idiom":"mac",\n"filename":"appicon_256.png",\n"scale":"2x"\n},\n{\n"size":"256x256",\n"idiom":"mac",\n"filename":"appicon_256.png",\n"scale":"1x"\n},\n{\n"size":"256x256",\n"idiom":"mac",\n"filename":"appicon_512.png",\n"scale":"2x"\n},\n{\n"size":"512x512",\n"idiom":"mac",\n"filename":"appicon_512.png",\n"scale":"1x"\n},\n{\n"size":"512x512",\n"idiom":"mac",\n"filename":"appicon_1024.png",\n"scale":"2x"\n}\n],\n"info":{\n"version":1,\n"author":"xcode"\n}\n}' > "./$2/Images.xcassets/AppIcon.appiconset/Contents.json"
echo "Complete!"
fi
@crishoj

This comment has been minimized.

Copy link

crishoj commented Nov 1, 2015

Thanks for this handy utility.

Please consider including these usability additions:
https://gist.github.com/crishoj/f08d9183caee9d6262a6/revisions

@chrisridd

This comment has been minimized.

Copy link

chrisridd commented Jan 7, 2016

This works great for us - thanks!

You need one more icon size now for the iPad Pro - add 167 to the list. The idiom is "ipad" and the scale is "2x".

@michaelhayman

This comment has been minimized.

Copy link

michaelhayman commented May 11, 2016

You can install the dependencies for this script on a Mac by running:

brew install imagemagick
brew install ghostscript

@richellis

This comment has been minimized.

Copy link

richellis commented Sep 14, 2016

Thanks for this, saved me a ton of work!
I incorporated forked changes from @crishoj and @giria plus a few tweaks of my own here: https://gist.github.com/richellis/09ccd6060d4e7ac7717d8767a2e27d39

Includes:

  • iPad Pro support
  • Dependency checks
  • Comment about Ghostscript dependency
  • Tips to install with Homebrew
  • Newline formatting in the JSON-generating code for better readability
@lilalinux

This comment has been minimized.

Copy link

lilalinux commented May 3, 2017

In current Xcode (8.3.2), Images.xcassets has been renamed to Assets.xcassets
Additionally, I suggest removing the ./ before $2 to allow for absolute paths

Thx for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.