Skip to content

Instantly share code, notes, and snippets.

@sharjeelaziz
Created April 22, 2011 17:34
Show Gist options
  • Save sharjeelaziz/937171 to your computer and use it in GitHub Desktop.
Save sharjeelaziz/937171 to your computer and use it in GitHub Desktop.
Generate ImageInfo.plist for all the images in the current directory
#!/bin/sh
# Requires ImageMagick
# Updates ImageInfo.plist -- plist file should already exist
# and initialized as /usr/libexec/PlistBuddy -c "Clear array" ImageInfo.plist
IMAGEINFOFILE="ImageInfo.plist"
/usr/libexec/PlistBuddy -c "Clear array" $IMAGEINFOFILE
INDEX=0
for f in *.png;
do
WIDTH=`identify $f | sed -E 's/.* ([0-9]+)x[0-9]+ .*/\1/'`
HEIGHT=`identify $f | sed -E 's/.* [0-9]+x([0-9]+) .*/\1/'`
echo "Processing $f $INDEX $WIDTH $HEIGHT"
/usr/libexec/PlistBuddy -c "Add :$INDEX:name string ${f/.png}" $IMAGEINFOFILE
/usr/libexec/PlistBuddy -c "Add :$INDEX:height real $HEIGHT" $IMAGEINFOFILE
/usr/libexec/PlistBuddy -c "Add :$INDEX:width real $WIDTH" $IMAGEINFOFILE
INDEX=`expr $INDEX + 1`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment