Skip to content

Instantly share code, notes, and snippets.

@maboloshi
Created February 15, 2019 11:46
Show Gist options
  • Save maboloshi/9c6efbb95a5d0479699aacd4dd12284a to your computer and use it in GitHub Desktop.
Save maboloshi/9c6efbb95a5d0479699aacd4dd12284a to your computer and use it in GitHub Desktop.
[快速生成 Mac App icns 图标 -- PNG2ICONS ] 需要准备一个 1024x1024 的png图片, 使用`png2icons.sh xxx.png`. 出处:http://www.jianshu.com/p/e74047f7cc91
#!/bin/bash
iconset_dir=tmp-$RANDOM.iconset
mkdir $iconset_dir
## 全部拷贝到命令行回车执行,执行结束之后去tmp.iconset查看十张图片是否生成好
sips -z 16 16 $1 --out $iconset_dir/icon_16x16.png &> /dev/null
sips -z 32 32 $1 --out $iconset_dir/[email protected] &> /dev/null
sips -z 32 32 $1 --out $iconset_dir/icon_32x32.png &> /dev/null
sips -z 64 64 $1 --out $iconset_dir/[email protected] &> /dev/null
sips -z 128 128 $1 --out $iconset_dir/icon_128x128.png &> /dev/null
sips -z 256 256 $1 --out $iconset_dir/[email protected] &> /dev/null
sips -z 256 256 $1 --out $iconset_dir/icon_256x256.png &> /dev/null
sips -z 512 512 $1 --out $iconset_dir/[email protected] &> /dev/null
sips -z 512 512 $1 --out $iconset_dir/icon_512x512.png &> /dev/null
sips -z 1024 1024 $1 --out $iconset_dir/[email protected] &> /dev/null
# 生成icns文件
iconutil -c icns $iconset_dir -o "${1%%.*}.icns"
[ -f "${1%%.*}.icns" ] && echo OK! || echo FAIL!!!
rm -r $iconset_dir
@maboloshi
Copy link
Author

${1%%.*} 此处的1 是变量名, 而不是代表数字1
1变量储存的是终端的第1个参数(即 xxx.png)。

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