├── LICENSE ├── README.md ├── blurmaker ├── res ├── sample-01.png ├── sample-02.png ├── sample-03.png └── sample-04.png └── watermark_icon.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 小鱼周凌宇 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # watermark_icon.sh 2 | 3 | ## 简介 4 | 5 | `watermark_icon.sh` 是一个可以帮助快速定位 commit 的脚本,可以用用于 Xcode Run Script 中。 6 | 7 | `watermark_icon.sh` 可以为在 build 后将原有的图标覆盖上 `添加了 build 号、commit 的 hash 值、分支名的` 水印。 8 | 9 | ![](res/sample-01.png) 10 | 11 | App LOGO 图片来自[花瓣](http://huaban.com/pins/571816999/) 12 | 13 | > 此 repo 是个人练习时候写的脚本,如果需要更强大的功能,强烈推荐 [KZBootstrap, a powerful project setup aimed at high quality code.](https://github.com/krzysztofzablocki/KZBootstrap) 14 | 15 | ## 安装 16 | 17 | 1. 将 `watermark_icon.sh` 放置到 Xcode 工程目录下 18 | 2. `Build Phases` -> `New Run Script Phase` 添加 Run Script 19 | 3. shell 内容填写 `"${SRCROOT}/watermark_icon.sh"` 20 | 21 | ![](res/sample-03.png) 22 | 23 | ![](res/sample-04.png) 24 | 25 | ## 使用 26 | 27 | Debug 或 ADHoc 下,Run 之后可以看到安装好的 App 图标已经添加了水印。 28 | 29 | # blurmaker 30 | 31 | ## 简介 32 | 33 | `blurmaker` 是一个为图片添加水印的 command line 工具。 34 | 35 | ## 安装 36 | 37 | Mac OS 38 | 39 | ``` 40 | $ sudo cp blurmaker /usr/local/sbin 41 | ``` 42 | 43 | ## 使用 44 | 45 | ``` 46 | $ blurmaker -i yourimage -s "your text" 47 | ``` 48 | 49 | ![](res/sample-02.png) 50 | 51 | App LOGO 图片来自[花瓣](http://huaban.com/pins/571817001/) 52 | 53 | 54 | -------------------------------------------------------------------------------- /blurmaker: -------------------------------------------------------------------------------- 1 | export PATH=/opt/local/bin/:/opt/local/sbin:$PATH:/usr/local/bin: 2 | 3 | # blurmaker -i xxx.png -s "sign" 4 | 5 | convertPath=`which convert` 6 | imagePath="" 7 | caption="" 8 | 9 | if [ ! -f ${convertPath} ]; then 10 | echo "============== 11 | WARNING: 你需要先安装 ImageMagick!!!!: 12 | brew install imagemagick 13 | ==============" 14 | exit 0; 15 | fi 16 | 17 | while getopts 'i:s:' arg 18 | do 19 | case $arg in 20 | i) 21 | # 保存图片 22 | imagePath=$OPTARG 23 | ;; 24 | s) 25 | caption=$OPTARG 26 | ;; 27 | esac 28 | done 29 | 30 | function generateIcon() { 31 | originalImg=$1 32 | caption=$2 33 | 34 | # 验证存在性 35 | 36 | if [ ! -f ${originalImg} ]; then 37 | echo 图片不存在 38 | exit 0; 39 | fi 40 | 41 | # 添加高斯模糊 42 | convert ${originalImg} -blur 10x8 blur-original.png 43 | 44 | # 截取下部分 45 | width=`identify -format %w ${originalImg}` 46 | height=`identify -format %h ${originalImg}` 47 | height_0=`expr ${height} / 2` 48 | height_1=$((${height} - ${height_0})) 49 | convert blur-original.png -crop ${width}x${height_0}+0+${height_1} crop-blur-original.png 50 | 51 | # 加字 52 | point_size=$(((8 * $height) / 58)) 53 | 54 | convert -background none -fill white -pointsize ${point_size} -gravity center caption:"${caption}" crop-blur-original.png +swap -composite label.png 55 | 56 | # 合成 57 | composite -geometry +0+${height_0} label.png ${originalImg} watermark.png 58 | 59 | # 清除文件 60 | rm blur-original.png 61 | rm crop-blur-original.png 62 | rm label.png 63 | } 64 | 65 | generateIcon ${imagePath} ${caption} 66 | -------------------------------------------------------------------------------- /res/sample-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summertian4/ZLYWatermarkIcon/f76ee34f28b59b679945c73741dddd62f3fc9c18/res/sample-01.png -------------------------------------------------------------------------------- /res/sample-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summertian4/ZLYWatermarkIcon/f76ee34f28b59b679945c73741dddd62f3fc9c18/res/sample-02.png -------------------------------------------------------------------------------- /res/sample-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summertian4/ZLYWatermarkIcon/f76ee34f28b59b679945c73741dddd62f3fc9c18/res/sample-03.png -------------------------------------------------------------------------------- /res/sample-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summertian4/ZLYWatermarkIcon/f76ee34f28b59b679945c73741dddd62f3fc9c18/res/sample-04.png -------------------------------------------------------------------------------- /watermark_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 | caption="${buildNumber} \n${branch}\n${commit}" 18 | 19 | echo "caption: ${caption}" 20 | echo "product_path: ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" 21 | 22 | # Release 不执行 23 | echo "Configuration: $CONFIGURATION" 24 | if [ ${CONFIGURATION} = "Release" ]; then 25 | exit 0; 26 | fi 27 | 28 | function generateIcon() { 29 | originalImg=$1 30 | 31 | cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 32 | 33 | # 验证存在性 34 | if [[ ! -f ${originalImg} || -z ${originalImg} ]]; then 35 | return; 36 | fi 37 | 38 | # 进入编译后的工程目录 39 | cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" 40 | 41 | # 添加高斯模糊 42 | convert ${originalImg} -blur 10x8 blur-original.png 43 | 44 | # 截取下部分 45 | width=`identify -format %w ${originalImg}` 46 | height=`identify -format %h ${originalImg}` 47 | height_0=`expr ${height} / 2` 48 | height_1=$((${height} - ${height_0})) 49 | convert blur-original.png -crop ${width}x${height_0}+0+${height_1} crop-blur-original.png 50 | 51 | # 加字 52 | point_size=$(((8 * $width) / 58)) 53 | 54 | convert -background none -fill white -pointsize ${point_size} -gravity center caption:"${caption}" crop-blur-original.png +swap -composite label.png 55 | 56 | # 合成 57 | composite -geometry +0+${height_0} label.png ${originalImg} ${originalImg} 58 | 59 | # 清除文件 60 | rm blur-original.png 61 | rm crop-blur-original.png 62 | rm label.png 63 | } 64 | 65 | icon_count=`/usr/libexec/PlistBuddy -c "Print CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}" | wc -l` 66 | 67 | 68 | # Array { 69 | # AppIcon29x29 70 | # AppIcon40x40 71 | # AppIcon60x60 72 | # } 73 | # -2 的原因是因为输出是五行 74 | real_icon_index=$((${icon_count} - 2)) 75 | 76 | # ========= for ========= 77 | for ((i=0; i<$real_icon_index; i++)); do 78 | # 去 plist 中顺着路径找到 icon 名 79 | icon=`/usr/libexec/PlistBuddy -c "Print CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles:$i" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"` 80 | 81 | echo "icon: ${icon}" 82 | 83 | if [[ $icon == *.png ]] || [[ $icon == *.PNG ]] 84 | then 85 | generateIcon $icon 86 | else 87 | generateIcon "${icon}.png" 88 | generateIcon "${icon}@2x.png" 89 | generateIcon "${icon}@3x.png" 90 | fi 91 | 92 | done 93 | # ========= end for ========= 94 | --------------------------------------------------------------------------------