2012-01-12 16:28:20 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
source bashlib
|
2013-04-22 04:57:17 +00:00
|
|
|
cd "${0%/*}/../MasterPassword/Resources/Media"
|
|
|
|
PATH+=:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
|
2012-05-20 17:17:22 +00:00
|
|
|
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
|
|
|
|
2013-04-22 04:57:17 +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"
|
2013-04-22 04:57:17 +00:00
|
|
|
[512]="iTunesArtwork"
|
2012-01-12 16:28:20 +00:00
|
|
|
)
|
2013-04-22 04:57:17 +00:00
|
|
|
for size in $(reverse "${!icons[@]}"); do
|
2012-01-12 16:28:20 +00:00
|
|
|
file=${icons[size]}
|
|
|
|
|
2013-04-22 04:57:17 +00:00
|
|
|
if [[ "iTunesArtwork@2x" -nt $file ]]; then
|
2012-05-20 17:17:22 +00:00
|
|
|
pinf "$file ($size px)"
|
2013-04-22 04:57:17 +00:00
|
|
|
downsize "iTunesArtwork@2x" "$file" "${size}x${size}"
|
2012-05-20 17:17:22 +00:00
|
|
|
fnip
|
|
|
|
fi
|
2012-01-12 16:28:20 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
2013-04-22 04:57:17 +00:00
|
|
|
|
|
|
|
inf "Populating iconsets"
|
|
|
|
icons=(
|
|
|
|
"icon_512x512.png"
|
|
|
|
"icon_256x256@2x.png"
|
|
|
|
"icon_256x256.png"
|
|
|
|
"icon_128x128@2x.png"
|
|
|
|
"icon_128x128.png"
|
|
|
|
"icon_32x32@2x.png"
|
|
|
|
"icon_32x32.png"
|
|
|
|
"icon_16x16@2x.png"
|
|
|
|
"icon_16x16.png"
|
|
|
|
)
|
|
|
|
for iconset in *.iconset; do
|
|
|
|
[[ -d $iconset ]] || continue
|
|
|
|
|
|
|
|
for dest in "${icons[@]}"; do
|
|
|
|
src=$iconset/icon_512x512@2x.png
|
|
|
|
dest=$iconset/$dest
|
|
|
|
IFS='_x@.' read _ _ points scale _ <<< "${dest##*/}"
|
|
|
|
[[ $scale = *[^[:digit:]]* ]] && scale=1
|
|
|
|
size=$(( points * scale ))
|
|
|
|
|
|
|
|
if [[ ! -e $dest || "$src" -nt "$dest" ]]; then
|
|
|
|
pinf "$src -> $dest ($size px)"
|
|
|
|
downsize "$src" "$dest" "$size"
|
|
|
|
fnip
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
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
|
2013-04-22 04:57:17 +00:00
|
|
|
if [[ ! -e $dest || "$dest" -ot "$file" ]]; then
|
2012-05-20 17:17:22 +00:00
|
|
|
pinf "$file -> $dest"
|
|
|
|
downsize "$file" "$dest"
|
|
|
|
fnip
|
|
|
|
fi
|
|
|
|
done
|