Skip to content

Instantly share code, notes, and snippets.

@pdc-frans
Created August 9, 2016 17:03
Show Gist options
  • Save pdc-frans/2ec317823817bacf3df20a0e6d42572f to your computer and use it in GitHub Desktop.
Save pdc-frans/2ec317823817bacf3df20a0e6d42572f to your computer and use it in GitHub Desktop.
#!/bin/bash
#Recently switched an in-house level app with 20+ targets to universal app so we were in need to update 200+ icons,
#this is a small quick and dirty script used to resize all icons to what ios expects, checking Contents.json (solves warnings).
#WARNING USE IT AT YOUR OWN RISK!!
#Please note that this may downscale or upscale your images based on the original ones.
#Must be run at Images.xcassets level
#Requirements
# jq for JSON parsing
# imagemagick for image rescaling
for d in *.appiconset; do
cd "$d" #push folder
if [ $? -ne 0 ]; then
echo "Could not change folder"
exit 1
fi
FILELIST=`cat Contents.json |jq -r '.images | map(.filename) | join("\n")'`
for f in $FILELIST; do
FILESIZE=`cat Contents.json | jq --arg f "$f" '.images[] | select(.filename==$f) | .size'|replace \" ""|cut -dx -f1`
FILESCALE=`cat Contents.json | jq --arg f "$f" '.images[] | select(.filename==$f) | .scale'|replace \" ""|cut -dx -f1`
FILESIDE=`bc -l <<< "$FILESIZE * $FILESCALE"` #Calculate size based on scale and size property
convert $f -resize ${FILESIDE}x${FILESIDE} $f
done
cd .. #back to root
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment