Last active
December 28, 2015 09:59
-
-
Save sag333ar/7482853 to your computer and use it in GitHub Desktop.
Put all 2x images in proper folder-structure. Open terminal & cd to parent-directory of images folder. Run following script to generate XCAssets.
View article - http://sugartin.info/2013/10/18/shell-script-for-genrating-xcassets-for-projects/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
createImagesets() { | |
for d in *; do | |
if [ -d $d ] ; then | |
(cd $d; createImagesets) | |
fi | |
if [ -f $d ] ; then | |
a=${d%@2x.*}; | |
dirname=$a".imageset"; | |
mkdir $dirname; | |
mv $d $dirname; | |
fi | |
done | |
} | |
duplicateFiles() { | |
for d in *; do | |
if [ -d $d ] ; then | |
(cd $d; duplicateFiles) | |
fi | |
if [ -f $d ] ; then | |
a=${d%@2x.*}; | |
a=$a".png"; | |
cp $d $a; | |
fi | |
done | |
} | |
resize_non2xfiles() { | |
for d in *; do | |
if [ -d $d ] ; then | |
(cd $d; resize_non2xfiles) | |
fi | |
if [ -f $d ] ; then | |
if [ $d == "${d/@2x.png/}" ] ; then | |
width=`sips -g pixelWidth $d | tail -n1 | cut -d' ' -f4`; | |
height=`sips -g pixelHeight $d | tail -n1 | cut -d' ' -f4`; | |
name=`basename "$d"`; | |
width=$(expr $width / 2); | |
height=$(expr $height / 2); | |
sips -Z $width $height $d; | |
fi | |
fi | |
done | |
} | |
create_content_json() { | |
for d in *; do | |
if [ -d $d ] ; then | |
(cd $d; create_content_json) | |
if [ $d != "${d/.imageset/}" ]; then | |
filename0=${d%.*}; | |
filename1=$filename0".png"; | |
filename2=$filename0"@2x.png"; | |
echo "{\"images\":[{\"idiom\":\"universal\",\"scale\":\"1x\",\"filename\":\"$filename1\"},{\"idiom\":\"universal\",\"scale\":\"2x\",\"filename\":\"$filename2\"}],\"info\":{\"version\":1,\"author\":\"xcode\"}}" >> $d/Contents.json | |
fi | |
fi | |
done | |
} | |
createImagesets; | |
duplicateFiles; | |
resize_non2xfiles; | |
create_content_json; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment