Skip to content

Commit

Permalink
添加Shell文件
Browse files Browse the repository at this point in the history
  • Loading branch information
jianxiongc committed Mar 14, 2019
1 parent 7daeea5 commit 56e8c04
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Xcode-imageXcassets
命令行 将icon生成123x和Content.json文件

示例


```
sh imagesetGenerator.sh /Users/mac/Desktop/Script/images
```
83 changes: 83 additions & 0 deletions imagesetGenerator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/sh

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))


imageFile=$1
fileName2x=${imageFile/\.png/@2x\.png}
fileName3x=${imageFile/\.png/@3x\.png}

cp $imageFile $fileName3x
sips -z $height2x $width2x $1 --out $fileName2x
sips -z $height1x $width1x $1
}

Contents () {
imageFile=$1
renameFile2x=${imageFile/\.png/@2x\.png}
renameFile3x=${imageFile/\.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\"" : "\"$imageFile\"">> Contents.json
echo " "},>> Contents.json
echo " "{>> Contents.json
echo " \"idiom\"" : "\"universal\"",>> Contents.json
echo " \"scale\"" : "\"2x\"",>> Contents.json
echo " \"filename\"" : "\"$renameFile2x\"">> Contents.json
echo " "},>> Contents.json
echo " "{>> Contents.json
echo " \"idiom\"" : "\"universal\"",>> Contents.json
echo " \"scale\"" : "\"3x\"",>> Contents.json
echo " \"filename\"" : "\"$renameFile3x\"">> 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

}

cd $1
if [ ! -n "$1" ] ;then
echo "\033[31m 没有传入参数,需要执行的图片文件夹路径 \033[0m"
exit
else
echo "\033[32m 开始执行 \033[0m"
fi
# 1 遍历$1文件夹下的所有文件,即所有图片素材了。
for file in ./*
do
# 2 获取图片的文件名,并生成 “文件名.imageset”文件夹,方便下一步处理
imageFile=$(basename $file)
imageDir=${imageFile/\.png/\.imageset}
mkdir $imageDir

# 3 将图片拷贝入“文件名.imageset”文件夹,并进入该文件夹
cp $imageFile $imageDir/
cd $imageDir

# 4 执行ScalePic函数,将图片文件名作为参数。
# 执行Contents函数,生成描述文件Contents.json
# 最后处理完后,退回上一级目录
ScalePic $imageFile
Contents $imageFile
cd ..
done
echo "\033[32m 完成 \033[0m"
cd ..

0 comments on commit 56e8c04

Please sign in to comment.