Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@benvium
Last active January 12, 2021 10:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benvium/2be6d673aa9ac284bb8a to your computer and use it in GitHub Desktop.
Save benvium/2be6d673aa9ac284bb8a to your computer and use it in GitHub Desktop.
Generate app icons and xcassets file from a single image. To use this, place script in `appname` folder inside your project (i.e. the folder that Xcode generates for you containing your source code, it's named after whatever you called the app). Create folder there called `RawImages`. Source icon should 1024x1024 and be called appIcon.png. If th…
#!/bin/bash -e
# --------------------------------------------------------
# Generate app icons and xcassets file from a single image
# Ben Clayton, Calvium Ltd.
# --------------------------------------------------------
# To use this, place script in `appname` folder inside your project (i.e. the folder that Xcode generates for you containing your source code, it's named after whatever you called the app).
# Create folder there called `RawImages`.
# Source icon should 1024x1024 and be called appIcon.png. If the icon changes, you can just run this again to regenerate everything.
# This script assumes that you have the default setup of an Images.xcassets file containing the AppIcon.appiconset.
# Adjust iconPath below if you use something different
sourceIconName="RawImages/appIcon.png"
# Ensure we're running in location of script.
#cd "`dirname $0`"
# Check imagemagick is installed
# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
command -v convert >/dev/null 2>&1 || { echo >&2 "I require imagemagick but it's not installed. Aborting."; exit 1; }
iconPath="Images.xcassets/AppIcon.appiconset"
mkdir -p "$iconPath"
# clean it out
rm -rf $iconPath/*.png
# iPhone and iPad iOS7+ Sizes
convert $sourceIconName -resize 120x120 $iconPath/appicon-60@2x.png
convert $sourceIconName -resize 180x180 $iconPath/appicon-60@3x.png
convert $sourceIconName -resize 76x76 $iconPath/appicon-76.png
convert $sourceIconName -resize 152x152 $iconPath/appicon-76@2x.png
convert $sourceIconName -resize 40x40 $iconPath/appicon-Small-40.png
convert $sourceIconName -resize 80x80 $iconPath/appicon-Small-40@2x.png
convert $sourceIconName -resize 120x120 $iconPath/appicon-Small-40@3x.png
convert $sourceIconName -resize 29x29 $iconPath/appicon-Small.png
convert $sourceIconName -resize 58x58 $iconPath/appicon-Small@2x.png
convert $sourceIconName -resize 87x87 $iconPath/appicon-Small@3x.png
cat > "$iconPath/Contents.json" << EOF
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
,"filename" : "appicon-60@2x.png"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
,"filename" : "appicon-60@3x.png"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
,"filename" : "appicon-76.png"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
,"filename" : "appicon-76@2x.png"
},
{
"idiom" : "iphone",
"scale" : "1x",
"size" : "29x29"
,"filename" : "appicon-Small.png"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
,"filename" : "appicon-Small@2x.png"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
,"filename" : "appicon-Small@3x.png"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
,"filename" : "appicon-Small-40@2x.png"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
,"filename" : "appicon-Small-40@3x.png"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
,"filename" : "appicon-Small-40.png"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
,"filename" : "appicon-Small-40@2x.png"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
,"filename" : "appicon-Small.png"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
,"filename" : "appicon-Small@2x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"pre-rendered" : true
}
}
EOF
@pkasson
Copy link

pkasson commented Nov 12, 2015

Have been looking for a generator ... but when I tried this, I got:

convert: unable to open image `Images.xcassets/AppIcon.appiconset/appicon-60@2x.png': No such file or directory @ error/blob.c/OpenBlob/2695.

The project folder name does have a space in it, but that should not matter right ?

@benvium
Copy link
Author

benvium commented Dec 10, 2015

@pkasson Ah, it assumes the Images.xcassets/AppIcon.appiconset folder exists. I've updated the gist

@f8ttyc8t
Copy link

I've slightly modified script to fit never xcode versions.
Would be my pleasure to share with you - just tell me how...

@roblabs
Copy link

roblabs commented Oct 6, 2017

Update for Xcode Version 9.0 (9A235), which requires a 1024x1024 for "idiom": "ios-marketing",

https://gist.github.com/roblabs/527458cbe46b0483cd2d594c7b9e583f

Thanks @benvium, we've been using this script for several Xcode projects over the year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment