生成Mac App icons

2020-11-11  本文已影响0人  Joshua520

最近使用自己开发的Mac自动配置打包工具,没有icon就觉的很丑,考虑之前用sips切割图片生成应用的icon,现修改下用来生成Mac App的图标,简单记录如下。

1 、准备一个1024*1024的png图片(可以是其他更小的图片比如:512 * 512)
2、拷贝切图脚本,并命名为mac-icon.sh

#!/bin/sh

Contents(){
cat <<EOF >./AppIcon.appiconset/Contents.json
   {
      "images" : [
        {
          "filename" : "icon_16x16.png",
          "idiom" : "Mac",
          "scale" : "1x",
          "size" : "16x16"
        },
        {
          "filename" : "icon_16x16@2x.png",
          "idiom" : "Mac",
          "scale" : "2x",
          "size" : "16x16"
        },
        {
          "filename" : "icon_32x32.png",
          "idiom" : "Mac",
          "scale" : "1x",
          "size" : "32x32"
        },
        {
          "filename" : "icon_32x32@2x.png",
          "idiom" : "Mac",
          "scale" : "2x",
          "size" : "32x32"
        },
        {
          "filename" : "icon_128x128.png",
          "idiom" : "Mac",
          "scale" : "1x",
          "size" : "128x128"
        },
        {
          "filename" : "icon_128x128@2x.png",
          "idiom" : "Mac",
          "scale" : "2x",
          "size" : "128x128"
        },
        {
          "filename" : "icon_256x256.png",
          "idiom" : "Mac",
          "scale" : "1x",
          "size" : "256x256"
        },
        {
          "filename" : "icon_256x256@2x.png",
          "idiom" : "Mac",
          "scale" : "2x",
          "size" : "256x256"
        },
        {
          "filename" : "icon_512x512.png",
          "idiom" : "Mac",
          "scale" : "1x",
          "size" : "512x512"
        },
        {
          "filename" : "icon_512x512@2x.png",
          "idiom" : "Mac",
          "scale" : "2x",
          "size" : "512x512"
        }
      ],
      "info" : {
        "author" : "Xcode",
        "version" : 1
      }
    }

EOF
}

setIconImage(){
    echo "开始生成图标······"
    sips -z 16 16     "$1" --out ./AppIcon.appiconset/icon_16x16.png
    sips -z 32 32     "$1" --out ./AppIcon.appiconset/icon_16x16@2x.png
    sips -z 32 32     "$1" --out ./AppIcon.appiconset/icon_32x32.png
    sips -z 64 64     "$1" --out ./AppIcon.appiconset/icon_32x32@2x.png
    sips -z 128 128   "$1" --out ./AppIcon.appiconset/icon_128x128.png
    sips -z 256 256   "$1" --out ./AppIcon.appiconset/icon_128x128@2x.png
    sips -z 256 256   "$1" --out ./AppIcon.appiconset/icon_256x256.png
    sips -z 512 512   "$1" --out ./AppIcon.appiconset/icon_256x256@2x.png
    sips -z 512 512   "$1" --out ./AppIcon.appiconset/icon_512x512.png
    sips -z 1024 1024   "$1" --out ./AppIcon.appiconset/icon_512x512@2x.png
    echo "全部图标生成······"
}

mkdir AppIcon.appiconset
if [ -n "$1" ] ; then
    echo "icon地址: $1"
else
    echo "icon不能为空"
   exit 1
fi
Contents
setIconImage "$1"

3、执行脚本

sh ./mac-icon.sh /Users/eddy/Desktop/lib/pic.png

4、将生成AppIcon.appiconset拷贝到工程


AppIcon.appiconset.png

可以自行添加rm指令,使其支持直接拷贝到工程对应的位置,来简化手动操作。

上一篇 下一篇

猜你喜欢

热点阅读