Created
April 9, 2019 10:56
-
-
Save iSapozhnik/5ccc4dc05abf97d5aeea1ace6625861c to your computer and use it in GitHub Desktop.
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