-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7daeea5
commit 56e8c04
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 | ||
``` |
This file contains 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
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 .. |