Skip to content

Instantly share code, notes, and snippets.

@lyqflnh
Last active March 12, 2017 03:18
Show Gist options
  • Save lyqflnh/4906235863d977b577341411ae5c0312 to your computer and use it in GitHub Desktop.
Save lyqflnh/4906235863d977b577341411ae5c0312 to your computer and use it in GitHub Desktop.
倍图生成器
#!/bin/sh
#--------------------------
# 倍图生成器
#
# version:1.1
# create buy MQ on 17/03/01
#--------------------------
# ⚠️steal idea from 技术渔场: http://www.tallmantech.com/13/
IFS=$'\n'
ScalePic () {
imageHeight=`sips -g pixelHeight $1 | awk -F": " '{print $2}'`
imageWidth=`sips -g pixelWidth $1 | awk -F: '{print $2}'`
height=`echo $imageHeight`
width=`echo $imageWidth`
height2x=$(($height*2/3))
width2x=$(($width*2/3))
height1x=$(($height/3))
width1x=$(($width/3))
imageFileName=$1
imageFileName2x=${imageFileName/\.png/@2x\.png}
imageFileName3x=${imageFileName/\.png/@3x\.png}
cp $imageFileName $imageFileName3x
sips -z $height2x $width2x $1 --out $imageFileName2x
sips -z $height1x $width1x $1
}
Contents () {
imageFileName=$1
imageFileName2x=${imageFileName/\.png/@2x\.png}
imageFileName3x=${imageFileName/\.png/@3x\.png}
echo { >> Contents.json
echo " \"images\"" : [>> Contents.json
echo " "{>> Contents.json
echo " \"idiom\"" : "\"universal\"",>> Contents.json
echo " \"scale\"" : "\"1x\"",>> Contents.json
echo " \"filename\"" : "\"$imageFileName\"">> Contents.json
echo " "},>> Contents.json
echo " "{>> Contents.json
echo " \"idiom\"" : "\"universal\"",>> Contents.json
echo " \"scale\"" : "\"2x\"",>> Contents.json
echo " \"filename\"" : "\"$imageFileName2x\"">> Contents.json
echo " "},>> Contents.json
echo " "{>> Contents.json
echo " \"idiom\"" : "\"universal\"",>> Contents.json
echo " \"scale\"" : "\"3x\"",>> Contents.json
echo " \"filename\"" : "\"$imageFileName3x\"">> Contents.json
echo " "}>> Contents.json
echo " "],>> Contents.json
echo " \"info\"" : {>> Contents.json
echo " \"version\"" : 1,>> Contents.json
echo " \"author\"" : "\"xcode\"">> Contents.json
echo " "}>> Contents.json
echo }>> Contents.json
}
productDir=Product
if [ ! -d $productDir ]; then
mkdir $productDir
echo "$productDir 文件夹已创建"
else
echo "$productDir 文件夹已存在"
fi
for imageFilePath in ./*.png
do
imageFileName=$(basename $imageFilePath)
imagesetDir=${imageFileName/\.png/\.imageset}
# 有与.png文件对应的.imageset文件夹, continue
if [ -d ./$productDir/$imagesetDir ]
then
echo "⚠️ $imagesetDir exist"
continue
fi
cd $productDir
mkdir $imagesetDir
cp ../$imageFileName $imagesetDir/
cd $imagesetDir
# 新生成文件提示 Start
echo ""
echo "🔔 NEW-Start🔔 🚅 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 -- $imageFileName"
ScalePic $imageFileName
Contents $imageFileName
echo "🔔 NEW-End 🔔 🚅 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 🚌 -- $imageFileName"
echo ""
# 新生成文件提示 End
cd ..
cd ..
done
## 注释
# 2种if
# if [条件]; then
#
# fi
#
# if [条件]
# then
#
# fi
# update
# V1.1
# 文件夹内新增3倍图, 不用全部重新生成
# 新生成内容提示
@imfangwenjie
Copy link

6666666

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