引用文章https://www.jianshu.com/p/a37e114b7e66
进行了更新
-
效果图
- 安装ImageMagick
brew install imagemagick
brew 安装不成功,可以添加镜像,用阿里云或者清华镜像,mac新系统中在 .zshrc 文件中添加
# homebrew使用阿里云的镜像源
#export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles
# homebrew 清华镜像源
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
安装 字体,这个目前是必须的,如只图片合成图片,不需要字体
brew install ghostscript
安装后验证,必须有字体
identify -list font
操作步骤参照引用链接
icon添加编译号脚本更新
#!/bin/bash
echo "✅ ==========APPicon添加版本号开始=========="
#######################################################
# 1、检查是否安装了ImageMagick
#######################################################
echo " Checking installed ImageMagick"
convertPath=`which convert`
if [[ ! -f ${convertPath} || -z ${convertPath} ]]; then
convertValidation=true;
else
convertValidation=false;
fi
# 未安装 提示并退出
if [ "$convertValidation" == true ]; then
echo "❌ ImageMagick 未安装,请使用命令安装\n brew install imagemagick"
exit 0;
else
echo "✅ ImageMagick 已安装"
fi
######################################################
# 2. 全局字段
######################################################
echo "Product Name: ${PRODUCT_NAME}"
echo "Bundle Identifier: ${BUNDLE_IDENTIFIER}"
echo "Version: ${MARKETING_VERSION}"
echo "Build: ${CURRENT_PROJECT_VERSION}"
# Assets中的appIcon文件名
APPICON_NAME="AppIcon"
# Assets中Debug环境的appIcon文件名
DEBUG_APPICON_NAME="${APPICON_NAME}-Debug"
# # 获取app版本号
# APP_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "${INFOPLIST_FILE}")
# # 获取build号
# APP_BUILD_NUM=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "${INFOPLIST_FILE}")
# xcode11 最新写法
# 获取app版本号
APP_VERSION="$MARKETING_VERSION"
# 获取build号
APP_BUILD_NUM="$CURRENT_PROJECT_VERSION"
# Icon上显示的文字内容, 你可以在这里修改标题格式
CAPTION="$APP_VERSION\n($APP_BUILD_NUM)"
echo " DEBUG_APPICON_NAME=$DEBUG_APPICON_NAME"
echo " 版本号=$APP_VERSION"
echo " 编译号=$APP_BUILD_NUM"
######################################################
# 3. 复制AppIcon到AppIcon-Debug
######################################################
echo " Begin copy icon files"
# appicon路径
APPICON_SET_PATH=`find $SRCROOT -name "${APPICON_NAME}.appiconset"`
echo " APPICON_SET_PATH=$APPICON_SET_PATH"
if [ "$APPICON_SET_PATH" = "" ]; then
exitWithMessage "❌ Get APPICON_SET_PATH failed." 0
fi
# appicon_debug路径
ASSET_PATH=`echo $(dirname ${APPICON_SET_PATH})`
DEBUG_APPICON_SET_PATH="${ASSET_PATH}/${DEBUG_APPICON_NAME}.appiconset"
echo " DEBUG_APPICON_SET_PATH=$DEBUG_APPICON_SET_PATH"
if [ "$DEBUG_APPICON_SET_PATH" = "" ]; then
exitWithMessage "❌ Get DEBUG_APPICON_SET_PATH failed." 0
fi
# 删除appicon_debug里的文件
rm -rf $DEBUG_APPICON_SET_PATH
if [ $? != 0 ];then
exitWithMessage "❌ Remove ${DEBUG_APPICON_SET_PATH} failed." 0
fi
# 复制appicon到appicon_debug
cp -rf $APPICON_SET_PATH $DEBUG_APPICON_SET_PATH
if [ $? != 0 ];then
exitWithMessage "❌ Copy ${APPICON_NAME} to ${DEBUG_APPICON_NAME} failed." 0
fi
echo "✅ Finish copy icon files."
# # 处理icon,添加水印
# # Processing icon
function processIcon() {
BASE_IMAGE_PATH=$1
echo "BASE_IMAGE_PATH=$BASE_IMAGE_PATH"
BASE_FLODER_PATH=`dirname $BASE_IMAGE_PATH`
cd "$BASE_FLODER_PATH"
# 获取图片宽度
WIDTH=$(identify -format %w ${BASE_IMAGE_PATH})
echo "width $WIDTH"
FONT_SIZE=$(echo "$WIDTH * .15" | bc -l)
echo "font size $FONT_SIZE"
convert ${BASE_IMAGE_PATH} -font Helvetica -pointsize ${FONT_SIZE} \
-draw "gravity south \
fill white text 0,12 '$APP_VERSION($APP_BUILD_NUM)'" \
${BASE_IMAGE_PATH}
}
#######################################################
# 4. 处理AppIcon-Debug
#######################################################
find "$DEBUG_APPICON_SET_PATH" -type f -name "*.png" -print0 |
while IFS= read -r -d '' file; do
echo " ${file}"
# 调用 processIcon 方法
processIcon "${file}"
done
echo "✅ ==========APPicon添加版本号结束=========="
- 同理,在启动图添加编译号,使用LaunchScreen.storyboard,区别就是图片文件夹的后缀
#!/bin/bash
echo "✅ ==========启动图添加版本号开始=========="
#######################################################
# 1、检查是否安装了ImageMagick
#######################################################
echo " Checking installed ImageMagick"
convertPath=`which convert`
if [[ ! -f ${convertPath} || -z ${convertPath} ]]; then
convertValidation=true;
else
convertValidation=false;
fi
# 未安装 提示并退出
if [ "$convertValidation" == true ]; then
echo "❌ ImageMagick 未安装,请使用命令安装\n brew install imagemagick"
exit 0;
else
echo "✅ ImageMagick 已安装"
fi
######################################################
# 2. 全局字段
######################################################
echo "Product Name: ${PRODUCT_NAME}"
echo "Bundle Identifier: ${BUNDLE_IDENTIFIER}"
echo "Version: ${MARKETING_VERSION}"
echo "Build: ${CURRENT_PROJECT_VERSION}"
# Assets中的appIcon文件名
IMAGE_NAME="launch_image"
# Assets中Debug环境的appIcon文件名
BUNDLE_IMAGE_NAME="${IMAGE_NAME}-Build"
# # 获取app版本号
# APP_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "${INFOPLIST_FILE}")
# # 获取build号
# APP_BUILD_NUM=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "${INFOPLIST_FILE}")
# xcode11 最新写法
# 获取app版本号
APP_VERSION="$MARKETING_VERSION"
# 获取build号
APP_BUILD_NUM="$CURRENT_PROJECT_VERSION"
# Icon上显示的文字内容, 你可以在这里修改标题格式
CAPTION="$APP_VERSION\n($APP_BUILD_NUM)"
echo " BUNDLE_IMAGE_NAME=$BUNDLE_IMAGE_NAME"
echo " 版本号=$APP_VERSION"
echo " 编译号=$APP_BUILD_NUM"
######################################################
# 3. 复制AppIcon到AppIcon-Debug
######################################################
echo " Begin copy icon files"
# appicon路径 .imageset 后缀
APPICON_SET_PATH=`find $SRCROOT -name "${IMAGE_NAME}.imageset"`
echo " APPICON_SET_PATH=$APPICON_SET_PATH"
if [ "$APPICON_SET_PATH" = "" ]; then
exitWithMessage "❌ Get APPICON_SET_PATH failed." 0
fi
# appicon_debug路径 .imageset 后缀
ASSET_PATH=`echo $(dirname ${APPICON_SET_PATH})`
DEBUG_APPICON_SET_PATH="${ASSET_PATH}/${BUNDLE_IMAGE_NAME}.imageset"
echo " DEBUG_APPICON_SET_PATH=$DEBUG_APPICON_SET_PATH"
if [ "$DEBUG_APPICON_SET_PATH" = "" ]; then
exitWithMessage "❌ Get DEBUG_APPICON_SET_PATH failed." 0
fi
# 删除appicon_debug里的文件
rm -rf $DEBUG_APPICON_SET_PATH
if [ $? != 0 ];then
exitWithMessage "❌ Remove ${DEBUG_APPICON_SET_PATH} failed." 0
fi
# 复制appicon到appicon_debug
cp -rf $APPICON_SET_PATH $DEBUG_APPICON_SET_PATH
if [ $? != 0 ];then
exitWithMessage "❌ Copy ${IMAGE_NAME} to ${BUNDLE_IMAGE_NAME} failed." 0
fi
echo "✅ Finish copy icon files."
# # 处理icon,添加水印
# # Processing icon
function processIcon() {
BASE_IMAGE_PATH=$1
echo "BASE_IMAGE_PATH=$BASE_IMAGE_PATH"
BASE_FLODER_PATH=`dirname $BASE_IMAGE_PATH`
cd "$BASE_FLODER_PATH"
# 获取图片宽度
WIDTH=$(identify -format %w ${BASE_IMAGE_PATH})
echo "width $WIDTH"
FONT_SIZE=$(echo "$WIDTH * .15" | bc -l)
echo "font size $FONT_SIZE"
convert ${BASE_IMAGE_PATH} -font Helvetica -pointsize ${FONT_SIZE} \
-draw "gravity south \
fill white text 0,12 '$APP_VERSION($APP_BUILD_NUM)'" \
${BASE_IMAGE_PATH}
}
#######################################################
# 4. 处理AppIcon-Debug
#######################################################
find "$DEBUG_APPICON_SET_PATH" -type f -name "*.png" -print0 |
while IFS= read -r -d '' file; do
echo " ${file}"
# 调用 processIcon 方法
processIcon "${file}"
done
echo "✅ ==========启动图添加版本号结束=========="