2
0
MasterPassword/Scripts/convertImages

76 lines
2.0 KiB
Plaintext
Raw Normal View History

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
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
inf "Converting appiconsets"
2014-08-24 04:01:17 +00:00
declare -A icons=(
["Icon-60@2x.png"]=120
["Icon-40@2x.png"]=80
["Icon-40~ipad.png"]=40
["Icon-40~ipad@2x.png"]=80
["Icon-Small@2x.png"]=58
["Icon-Small~ipad.png"]=29
["Icon-Small~ipad@2x.png"]=58
["Icon-76~ipad.png"]=76
["Icon-76~ipad@2x.png"]=152
["icon_512x512.png"]=512
["icon_512x512@2x.png"]=1024
["icon_256x256@2x.png"]=512
["icon_256x256.png"]=256
["icon_128x128@2x.png"]=256
["icon_128x128.png"]=128
["icon_32x32@2x.png"]=64
["icon_32x32.png"]=32
["icon_16x16@2x.png"]=32
["icon_16x16.png"]=16
2012-01-12 16:28:20 +00:00
)
2014-08-24 04:01:17 +00:00
for name in "${!icons[@]}"; do
size=${icons[$name]}
file=Images.xcassets/AppIcon.appiconset/$name
2013-11-10 01:50:53 +00:00
echo "$PWD/$file"
2012-01-12 16:28:20 +00:00
2013-11-10 01:50:53 +00:00
if [[ "iTunesArtwork@2x.png" -nt $file ]]; then
pinf "$file ($size px)"
2013-11-10 01:50:53 +00:00
downsize "iTunesArtwork@2x.png" "$file" "${size}x${size}"
fnip
fi
2012-01-12 16:28:20 +00:00
done
2013-04-22 04:57:17 +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
[[ ! -e $file ]] && continue
2012-01-16 08:51:08 +00:00
dest=${file/@(@2x|-hd)}
dest=${dest/-ipadhd/-ipad}
2012-01-12 16:28:20 +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
pinf "$file -> $dest"
downsize "$file" "$dest"
fnip
fi
done