2012-01-12 16:28:20 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
source bashlib
|
2012-05-20 17:17:22 +00:00
|
|
|
cd "${0%/*}/../Resources"
|
|
|
|
PATH+=:/Applications/Xcode.app//Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
|
|
|
|
temp="${TMPDIR:-/tmp}/.$$.convertImages"
|
|
|
|
mkdir "$temp" || err "Couldn't create temp directory." || return
|
|
|
|
trap 'rmdir "$temp"' EXIT
|
|
|
|
|
|
|
|
downsize() {
|
|
|
|
local from=$1 to=$2 size=${3:-50%}
|
|
|
|
convert "$from" -filter box -resize "$size" -unsharp 1x1+1+0.4 "$to"
|
|
|
|
pngcrush -d "$temp" -rem gAMA -rem cHRM -rem sRGB -rem iCCP "$to" && mv "$temp/"* "$to"
|
|
|
|
}
|
2012-01-12 16:28:20 +00:00
|
|
|
|
2012-05-20 17:17:22 +00:00
|
|
|
inf "Converting iTunesArtwork"
|
2012-01-12 16:28:20 +00:00
|
|
|
icons=(
|
|
|
|
[57]="Icon.png"
|
|
|
|
[114]="Icon@2x.png"
|
2012-05-20 17:17:22 +00:00
|
|
|
[72]="Icon-72.png"
|
|
|
|
[144]="Icon-72@2x.png"
|
|
|
|
[29]="Icon-Small.png"
|
|
|
|
[58]="Icon-Small@2x.png"
|
|
|
|
[50]="Icon-Small-50.png"
|
|
|
|
[100]="Icon-Small-50@2x.png"
|
2012-01-12 16:28:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for size in "${!icons[@]}"; do
|
|
|
|
file=${icons[size]}
|
|
|
|
|
2012-05-20 17:17:22 +00:00
|
|
|
if [[ "iTunesArtwork.png" -nt $file ]]; then
|
|
|
|
pinf "$file ($size px)"
|
|
|
|
downsize "iTunesArtwork.png" "$file" "${size}x${size}"
|
|
|
|
fnip
|
|
|
|
fi
|
2012-01-12 16:28:20 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
2012-05-20 17:17:22 +00:00
|
|
|
hr
|
|
|
|
inf "Converting @2x/-hd artwork"
|
|
|
|
for file in ./**/*{@2x,-ipadhd,-hd}.png; do
|
2012-01-16 08:51:08 +00:00
|
|
|
inArray "${file##*/}" "${icons[@]}" && continue
|
2012-05-20 17:17:22 +00:00
|
|
|
[[ ! -e $file ]] && continue
|
2012-01-16 08:51:08 +00:00
|
|
|
|
2012-05-20 17:17:22 +00:00
|
|
|
dest=${file/@(@2x|-hd)}
|
|
|
|
dest=${dest/-ipadhd/-ipad}
|
2012-01-12 16:28:20 +00:00
|
|
|
|
2012-05-20 17:17:22 +00:00
|
|
|
if [[ $file = Default* ]]; then
|
|
|
|
read width height < <(identify -format '%w %h' "$file")
|
|
|
|
if (( width > height )); then
|
|
|
|
emit "Rotating $file" --
|
|
|
|
mogrify -rotate 90 "$file"
|
|
|
|
emit -$?
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ ! -e $dest || "$file" -nt "$dest" ]]; then
|
|
|
|
pinf "$file -> $dest"
|
|
|
|
downsize "$file" "$dest"
|
|
|
|
fnip
|
|
|
|
fi
|
|
|
|
done
|