You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode中用ImageMagick和GhostScript更新App图标验证不通过

App图标环境区分脚本验证失败排查求助

我尝试修改App图标以区分不同运行环境,参考相关教程及Stack Overflow帖子后,采用ImageMagick和GhostScript实现,但脚本的验证环节出现问题。Xcode提示需安装ImageMagick和GhostScript,但我已确认这两个工具已正确安装。附上Xcode报错截图、本地工具安装确认截图及使用的脚本,恳请协助排查解决。

脚本代码

# 942v's Script
#!/bin/sh
export PATH=/opt/local/bin/:/opt/local/sbin:$PATH:/usr/local/bin:

convertPath=`which convert`
gsPath=`which gs`

if [[ ! -f ${convertPath} || -z ${convertPath} ]]; then
  convertValidation=true;
else
  convertValidation=false;
fi

if [[ ! -f ${gsPath} || -z ${gsPath} ]]; then
  gsValidation=true;
else
  gsValidation=false;
fi

if [[ "$convertValidation" = true || "$gsValidation" = true ]]; then
  echo "WARNING: Skipping Icon versioning, you need to install ImageMagick and ghostscript (fonts) first, you can use brew to simplify process:"

  if [[ "$convertValidation" = true ]]; then
    echo "brew install imagemagick"
  fi
  if [[ "$gsValidation" = true ]]; then
    echo "brew install ghostscript"
  fi
exit 0;
fi

buildPlist=$INFOPLIST_FILE

version="$MARKETING_VERSION"
build_num="$CURRENT_PROJECT_VERSION"

IMAGES_RIBBON="${SRCROOT}/CompileImages/${CONFIGURATION}.png"

caption="$build_num"
echo $caption

function abspath() { pushd . > /dev/null; if [ -d "$1" ]; then cd "$1"; dirs -l +0; else cd "`dirname \"$1\"`"; cur_dir=`dirs -l +0`; if [ "$cur_dir" == "/" ]; then echo "$cur_dir`basename \"$1\"`"; else echo "$cur_dir/`basename \"$1\"`"; fi; fi; popd > /dev/null; }

function processIcon() {
    base_path=$1

    echo "base_path: $base_path"

    #this is the change
    target_path=$base_path


    width=`identify -format %w ${base_path}`
    height=`identify -format %h ${base_path}`

    band_height=$((($height * 20) / 100))
    band_position=$(($height - $band_height))
    text_position=$(($band_position - 3))
    point_size=$(((13 * $width) / 100))

    echo "Path: $IMAGES_RIBBON"
    echo "Image dimensions ($width x $height) - band height $band_height @ $band_position - point size $point_size"

    BASE_TMP_PATH="/tmp"

    #
    # blur band and text
    #
    convert $IMAGES_RIBBON -resize ${width}x${height} $BASE_TMP_PATH/ribbon.png

    convert ${base_path} -blur 10x8 $BASE_TMP_PATH/blurred.png
    convert $BASE_TMP_PATH/blurred.png -gamma 0 -fill white -draw "rectangle 0,$band_position,$width,$height" $BASE_TMP_PATH/mask.png
    convert -size ${width}x${band_height} xc:none -fill 'rgba(0,0,0,0.2)' -draw "rectangle 0,0,$width,$band_height" $BASE_TMP_PATH/labels-base.png
    convert -background none -size ${width}x${band_height} -pointsize $point_size -fill white -gravity center -gravity South caption:"$caption" $BASE_TMP_PATH/labels.png
    convert ${base_path} $BASE_TMP_PATH/blurred.png $BASE_TMP_PATH/mask.png -composite $BASE_TMP_PATH/temp.png

    rm $BASE_TMP_PATH/blurred.png
    rm $BASE_TMP_PATH/mask.png

    #
    # compose final image
    #
    filename=New${base_file}
    convert $BASE_TMP_PATH/temp.png $BASE_TMP_PATH/labels-base.png -geometry +0+$band_position -composite $BASE_TMP_PATH/labels.png -geometry +0+$text_position -geometry +${w}-${h} -composite $BASE_TMP_PATH/ribbon.png -composite "${target_path}"

    # clean up
    rm $BASE_TMP_PATH/temp.png
    rm $BASE_TMP_PATH/labels-base.png
    rm $BASE_TMP_PATH/labels.png
    rm $BASE_TMP_PATH/ribbon.png

    echo "Overlayed ${target_path}"
}




appiconset=$(find ${SRCROOT}/ -name AppIcon.appiconset)
echo "appiconset: $appiconset"


    if [ $CONFIGURATION = "Prod" ]; then
        find "$appiconset/icons/" -name '*.png' -exec cp '{}' "$appiconset/" \;
        echo "Exit"
        exit 0
    fi

if [ -d "$appiconset/icons/" ] 
then
    echo "Directory exists." 
    # get original icon to copy to assets
    find "$appiconset/icons/" -name '*.png' -exec cp '{}' "$appiconset/" \;
else
    # copy orgin to AppIcon
    rsync -rv  --include '*.png' --exclude '*' "$appiconset/" "$appiconset/icons/"
fi


for entry in "$appiconset"/*.png
do
  processIcon $entry
done

内容的提问来源于stack exchange,提问作者dbenitobaldeon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:55:18