imageMagick 和 PlistBuddy合体生成图标

demo地址

图片内容处理文件 (merchant-icon-generator.sh)

#获取参数 文件源
SRC_FILE="$1" 
#版本号
shortVersion="$2"
#标签number
bundlerNum="$3"

#转换      文件         绘制    坐标           填充       颜色          透明度             填充      坐标          填充      颜色           透明度            生成目标图片
convert "$SRC_FILE" -region 1024x244+0+780 -fill "rgb(0,159,250)" -colorize 100%   -region 1024x244+650+780 -fill "rgb(102,230,32)" -colorize 100%  target-new.png  

#转换       文件         重置坐标  地图坐标西南角  写入 白色字体,文字尺寸     绘制文字   offset    内容                    
convert target-new.png -gravity southwest -fill white -pointsize 230 -draw "text 60,-10 '$shortVersion'"  -gravity southeast -fill white -pointsize 230 -draw "text 60,-10 '$bundlerNum'" target-new.png

Plist处理文件(merchant_plist_generator.sh)

#!/bin/bash
appInfoPlistPath="Jovi/Jovi/Info-AdHoc.plist"
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${appInfoPlistPath})
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${appInfoPlistPath})

# url="$1"
# if [ "$1"  = "" ]
# then 
#   url="http://app.dp:8080/view/Merchant/job/dpmerchant_adhocMCI/lastBuild/buildNumber"
# fi
result="23232"
while [ "$result" == "" ]
do 
    result=$(curl -s "$url")
done

newBundleVersion=""$bundleShortVersion"."$result""
/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${newBundleVersion}"  ${appInfoPlistPath}

sh merchant-icon-generator.sh "1024-origin.png" "$bundleShortVersion" "$result"

图片生产(merchant-icon-generator.sh)

SRC_FILE="$1"
shortVersion="$2"
bundlerNum="$3"

convert "$SRC_FILE" -region 1024x254+0+770 -fill "rgb(0,159,250)" -colorize 100%   -region 1024x254+650+770 -fill "rgb(102,230,32)" -colorize 100%  target-new.png  
convert target-new.png -gravity southwest -fill white -font DINPro-Bold.otf -pointsize 230 -draw "text 60,-10 '$shortVersion'"  -gravity southeast -fill white -pointsize 230 -draw "text 60,-10 '$bundlerNum'" target-new.png

DST_PATH="Jovi/Jovi/JVImages.xcassets/AppIcon.appiconset/"

if [ ! -d "$DST_PATH" ];then
    mkdir -p "$DST_PATH"
fi

info() {
     local green="\033[1;32m"
     local normal="\033[0m"
     echo -e "[${green}INFO${normal}] $1"
}

error() {
     local red="\033[1;31m"
     local normal="\033[0m"
     echo -e "[${red}ERROR${normal}] $1"
}
SRC_FILE="target-new.png"

info 'Generate 1024x1024.png ...'
convert "$SRC_FILE" -resize 1024x1024 "$DST_PATH/1024x1024.png"

info 'Generate Icon-20.png ...'
convert "$SRC_FILE" -resize 40x40 "$DST_PATH/Icon-20@2x.png"
info 'Generate Icon-40@2x.png ...'
convert "$SRC_FILE" -resize 60x60 "$DST_PATH/Icon-20@3x.png"


info 'Generate Icon-60@2x.png ...'
convert "$SRC_FILE" -resize 120x120 "$DST_PATH/Icon-60@2x.png"
info 'Generate Icon-60@3x.png ...'
convert "$SRC_FILE" -resize 180x180 "$DST_PATH/Icon-60@3x.png"



info 'Generate Icon-Small.png ...'
convert "$SRC_FILE" -resize 29x29 "$DST_PATH/Icon-Small.png"
convert "$SRC_FILE" -resize 58x58 "$DST_PATH/Icon-Small@2x.png"
info 'Generate Icon-Small-40@3x.png ...'
convert "$SRC_FILE" -resize 87x87 "$DST_PATH/Icon-Small@3x.png"



info 'Generate Icon-Spotlight-40@2x.png ...'
convert "$SRC_FILE" -resize 80x80 "$DST_PATH/Icon-Spotlight-40@2x.png"
info 'Generate Icon@2x.png ...'
convert "$SRC_FILE" -resize 120x120 "$DST_PATH/Icon-Spotlight-40@3x.png"


info 'Generate Icon.png ...'
convert "$SRC_FILE" -resize 57x57 "$DST_PATH/Icon.png"
info 'Generate Icon-Small@2x.png ...'
convert "$SRC_FILE" -resize 114x114 "$DST_PATH/Icon@2x.png"


info 'Generate Done.'