herionliu 2019-06-26
之前用的一个批量导出APP图标和启动图的软件,今天发现收费了,于是自己造了个简单的轮子。
Mac上的sips
命令,可以很方便的帮助用户修改图片尺寸
Xcode里面的APP启动图资源包含两部分
所以这个脚本的功能就是两个
Contents.json
使用echo
简单粗暴的写入
setContents(){ echo { >> ./AppIcon/Contents.json echo " \"images\"" : [>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"20x20\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"2x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_40x40.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"20x20\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"3x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_60x60.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"29x29\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"2x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_58x58.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"29x29\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"3x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_87x87.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"40x40\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"2x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_80x80.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"40x40\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"3x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_120x120.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"60x60\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"2x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_120x120.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"60x60\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"iphone\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"3x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_180x180.png\"">> ./AppIcon/Contents.json echo " "},>> ./AppIcon/Contents.json echo " "{>> ./AppIcon/Contents.json echo " \"size\"" : "\"1024x1024\"",>> ./AppIcon/Contents.json echo " \"idiom\"" : "\"ios-marketing\"",>> ./AppIcon/Contents.json echo " \"scale\"" : "\"1x\"",>> ./AppIcon/Contents.json echo " \"filename\"" : "\"icon_1024x1024.png\"">> ./AppIcon/Contents.json echo " "}>> ./AppIcon/Contents.json echo " "],>> ./AppIcon/Contents.json echo " \"info\"" : {>> ./AppIcon/Contents.json echo " \"version\"" : 1,>> ./AppIcon/Contents.json echo " \"author\"" : "\"xcode\"">> ./AppIcon/Contents.json echo " "}>> ./AppIcon/Contents.json echo }>> ./AppIcon/Contents.json }
iconWithSize() { sips -Z $1 icon.png --out ./AppIcon/icon_$1x$1.png }
mkdir AppIcon setContents for size in 40 58 60 80 87 120 180 1024 do iconWithSize $size done
下载对应的sh
文件,放到你想导出图片的目录下,将你的原图命名为icon.png
,然后在控制台中进入该目录,执行
sh AppIcon.sh
下载对应的sh
文件,放到你想导出图片的目录下,将你的原图命名为Default.png
,然后在控制台中进入该目录,执行
sh AppLaunch.sh
就可以得到你要的资源啦。
sips
命令修改图片尺寸sips -z 768 1024 xxx.png 修改后图片尺寸为1024x768
sips -Z 500 xxx.png
==保留图片比例,宽高不超过500。注意是大写的Z==。要想保留图片原始比例就得这样做,比如你有一张尺寸为750 x 1334
的图片,执行完上面这条命令后,图片尺寸就变成了281x500
sips -Z 300 *.png
只需要用*
作为通配符来代替图片名就可以了
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
test-f /etc/resolv.conf &&echo"File /etc/resolv.conf found."||echo"File /etc/resolv.conf not found."