Search code examples
xcodeshellimagemagick

Can't pass validation to update my app icon with imagemagick and ghoscript in xcode


I am trying to update the icon of my app to be able to differentiate in which environment it is, I have been guided by this tutorial and these othe post with similar problems working with ImageMagick and Ghostscript, however my problem is in the validation that I have in my script, but xcode they indicate that I have to install imagemagick and ghostscript, however I verify that I have it correctly installed, any ideas on how to fix it?

Error caught in xcode in report navigatorenter image description here

Console of my computer with the components correctly installedenter image description here

I attach the script that I am using

# 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

Solution

  • Based on the comments, you state that running which convert from the command line gives the result /opt/homebrew/bin/convert.

    Your script sets PATH to things other than /opt/homebrew/bin.

    Update your script so PATH is set as follows:

    export PATH=/opt/homebrew/bin:/opt/local/bin:/opt/local/sbin:$PATH:/usr/local/bin: