iphone用の画像@2x.pngから通常のを生成

面倒なので、画像はretina用のみ作成して半分のサイズは「sips」コマンドを使用して生成することにした。

#!/bin/sh

CMDNAME=`basename $0`
if [ $# -ne 1 ]; then
  echo "Usage: $CMDNAME dir" 1>&2
  exit 1
fi

#dir=.
dir=$1

find $dir -name "*@2x.png" | while read file;
do
  width=`sips --getProperty pixelWidth $file | sed -E "s/.*pixelWidth: ([0-9]+)/\1/g" | tail -1`
  width=`expr $width / 2`
  newFile=`echo $file | sed 's/@2x//'`
#  echo $file - $newFile
  srcAbspath=$(cd $(dirname "$file") && pwd)/$(basename "$file")
  distAbspath=$(cd $(dirname "$newFile") && pwd)/$(basename "$newFile")
  sips -s format png --resampleWidth $width $srcAbspath --out $distAbspath
done