├── AppIcon.png ├── AppIcon_blur.png ├── README.md ├── step01.png └── tzmark_icon.sh /AppIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToninZhao/TZMarkAppIcon/75a7a607a4965f7a7871b5a18f047e0091629e72/AppIcon.png -------------------------------------------------------------------------------- /AppIcon_blur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToninZhao/TZMarkAppIcon/75a7a607a4965f7a7871b5a18f047e0091629e72/AppIcon_blur.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TZMarkAppIcon 2 | ### 步骤: 3 | #### 如果电脑没有安装*ImageMagick*,在终端执行下面的命令: 4 | ``` 5 | brew install imagemagick 6 | ``` 7 | #### 然后在回到项目工程目录,进行如下操作: 8 | __1.将 shell脚本放在项目的根目录下(与 YourApp.xcodeproj 同一层)__ 9 | __2.YourAppName => TARGETS => YourAppName => Build Phases 点击左上角的'+'的图标,选择 New Run Script Phase__ 10 | 在 shell 下面的黑色输入框写上shell的路径: 11 | ``` 12 | "${SRCROOT}/tzmark_icon.sh" 13 | ``` 14 | 如下图所示: 15 | ![add_run_script](https://github.com/ToninZhao/TZMarkAppIcon/blob/master/step01.png "add_run_script") 16 | __3.修改 Xcode 默认设置__ 17 | ``` 18 | YourProjectName => PROJECT => 选中项目 => build setting => Compress Png Files => Debug 的属性由 No 改为 Yes. 19 | YourProjectName => PROJECT => 选中项目 => build setting => Remove Text Metadata From Png Files => Debug 的属性由 No 改为 Yes. 20 | ``` 21 | #### 最后,重新 build 项目. 22 | ![](https://github.com/ToninZhao/TZMarkAppIcon/blob/master/AppIcon.png) 23 | ![](https://github.com/ToninZhao/TZMarkAppIcon/blob/master/AppIcon_blur.png) 24 | -------------------------------------------------------------------------------- /step01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToninZhao/TZMarkAppIcon/75a7a607a4965f7a7871b5a18f047e0091629e72/step01.png -------------------------------------------------------------------------------- /tzmark_icon.sh: -------------------------------------------------------------------------------- 1 | export PATH=/opt/local/bin/:/opt/local/sbin:$PATH:/usr/local/bin: 2 | 3 | convertPath=`which convert` 4 | 5 | if [[ ! -f ${convertPath} || -z ${convertPath} ]]; then 6 | echo "============== 7 | WARNING: 你需要先安装 ImageMagick!!!!: 8 | brew install imagemagick 9 | ==============" 10 | exit 0; 11 | fi 12 | 13 | 14 | commit=`git rev-parse --short HEAD` 15 | branch=`git rev-parse --abbrev-ref HEAD` 16 | buildNumber=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"` 17 | buildDate=`date "+%Y-%m-%d"` 18 | buildTime=`date "+%H:%M:%S"` 19 | caption="${buildDate}\n${buildTime}\n${buildNumber}_${branch}\n${commit}" 20 | 21 | echo "caption: ${caption}" 22 | echo "product_path: ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" 23 | 24 | # Release 不执行 25 | echo "Configuration: $CONFIGURATION" 26 | if [ ${CONFIGURATION} = "Release" ]; then 27 | exit 0; 28 | fi 29 | 30 | function generateIcon() { 31 | originalImg=$1 32 | 33 | cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 34 | 35 | # 验证存在性 36 | if [[ ! -f ${originalImg} || -z ${originalImg} ]]; then 37 | return; 38 | fi 39 | 40 | # 进入编译后的工程目录 41 | cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" 42 | 43 | # 添加高斯模糊 44 | convert ${originalImg} -blur 10x8 blur-original.png 45 | 46 | # 截取下部分 47 | width=`identify -format %w ${originalImg}` 48 | height=`identify -format %h ${originalImg}` 49 | height_0=`expr ${height} / 3` 50 | height_1=$((${height} - ${height_0})) 51 | convert blur-original.png -crop ${width}x${height_1}+0+${height_0} crop-blur-original.png 52 | 53 | # 加字 54 | point_size=$(((8 * $height) / 58)) 55 | 56 | convert -background none -fill gray -pointsize ${point_size} -gravity center caption:"${caption}" crop-blur-original.png +swap -composite label.png 57 | 58 | # 合成 59 | composite -geometry +0+${height_0} label.png ${originalImg} ${originalImg} 60 | 61 | # 清除文件 62 | rm blur-original.png 63 | rm crop-blur-original.png 64 | rm label.png 65 | } 66 | 67 | icon_count=`/usr/libexec/PlistBuddy -c "Print CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}" | wc -l` 68 | 69 | 70 | # Array { 71 | # AppIcon29x29 72 | # AppIcon40x40 73 | # AppIcon60x60 74 | # } 75 | # -2 的原因是因为输出是五行 76 | real_icon_index=$((${icon_count} - 2)) 77 | 78 | # ========= for ========= 79 | for ((i=0; i<$real_icon_index; i++)); do 80 | # 去 plist 中顺着路径找到 icon 名 81 | icon=`/usr/libexec/PlistBuddy -c "Print CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles:$i" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"` 82 | 83 | echo "icon: ${icon}" 84 | 85 | if [[ $icon == *.png ]] || [[ $icon == *.PNG ]] 86 | then 87 | generateIcon $icon 88 | else 89 | generateIcon "${icon}.png" 90 | generateIcon "${icon}@2x.png" 91 | generateIcon "${icon}@3x.png" 92 | fi 93 | 94 | done 95 | # ========= end for ========= 96 | --------------------------------------------------------------------------------