欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

MAC中用Shell脚本批量裁剪各种尺寸的App图标

程序员文章站 2023-01-08 16:36:27
在app上架前,一次一次自己剪裁上架需要的各个尺寸的icon不是程序员该干的事,使用mac中自带的sips工具可以解决这个需求。关于sips,在终端中直接执行可以出现以下信...

在app上架前,一次一次自己剪裁上架需要的各个尺寸的icon不是程序员该干的事,使用mac中自带的sips工具可以解决这个需求。
关于sips,在终端中直接执行可以出现以下信息:

复制代码 代码如下:

sips 10.4.4 - scriptable image processing system.
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.
try 'sips --help' or 'sips --helpproperties' for help using this tool

它一个脚本图像处理系统,可用于查询和修改图像文件。
下面是刚写的ios app icon裁剪脚本,保存成一个.sh文件,在终端里输入sh xx.sh就可以执行了:
复制代码 代码如下:
#!/bin/sh

filename="icon.png"
dirname="cutimg"
name_array=("icon-29.png" "icon-29@2x.png" "icon-40@2x.png" "icon-57.png" "icon-57@2x.png" "icon-120.png")
size_array=("29" "58" "80" "57" "114" "120")

mkdir $dirname

for ((i=0;i<${#name_array[@]};++i)); do
    m_dir=$dirname/${name_array[i]}
    cp $filename $m_dir
    sips -z ${size_array[i]} $m_dir
done