👨🏻‍💻's 博客

慢品人间烟火色,闲观万事岁月长

0%

快速生成iOS应用的图标

目标

  • shell脚本自动生成应用的图标

前提

  • .png格式的图片进行缩小操作不会失真
  • 应用的图标尺寸是可预先确定

流程

Q: 如何调整图标尺寸?

找指令

寻找合适的指令,最好是系统自带的,搜索得知指令 sips 可用于调整图片的尺寸

1
2
3
4
5
6
7
8
$ man sips
NAME
sips -- scriptable image processing system.

DESCRIPTION
This tool is used to query or modify raster image files and ColorSync ICC
profiles. Its functionality can also be used through the "Image Events"
AppleScript suite.

sips 是一个可脚本化的图片执行系统,通常可用于查询或修改图片文件

1
2
3
4
-z pixelsH pixelsW
--resampleHeightWidth pixelsH pixelsW
Resample image at specified size. Image apsect ratio may be
altered.

sips 指令有个*-z*参数,后面跟调整后的尺寸高与宽

Q:如何确定有哪些尺寸?

应用图标尺寸

generate_app_icon.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

scale_config=(
"iTunesArtwork.png" 512
"iTunesArtwork@2x.png" 1024
"Icon-60@2x.png" 120
"Icon-60@3x.png" 180
"Icon-76.png" 76
"Icon-76@2x.png" 152
"Icon-Small-40.png" 40
"Icon-Small-40@2x.png" 80
"Icon-Small-40@3x.png" 120
"Icon-Small.png" 29
"Icon-Small@2x.png" 58
"Icon-Small@3x.png" 87
# extra
)

num=${#scale_config[@]}

for (( i = 0; i < num; i++ )); do
cache_img=${scale_config[i]}
cp logo.png ${cache_img}
i=$((${i}+1))
sips -Z ${scale_config[i]}x${scale_config[i]} ${cache_img}
done

代码

参考