Skip to content

Instantly share code, notes, and snippets.

@roana0229
Last active January 11, 2018 01:45
Show Gist options
  • Save roana0229/414ce9607f36d5c2f0f1157b538a4e3d to your computer and use it in GitHub Desktop.
Save roana0229/414ce9607f36d5c2f0f1157b538a4e3d to your computer and use it in GitHub Desktop.
iOS用の画像をリサイズするスクリプト

create-ios-all-size-images-shellscript

Generate ios all size images (.jpg or .png).

How to use

Run create_ios_all_size_images.command

  • Conventions for source file layout
.
├── create_ios_all_size_images.command
│
├── src    // Resize the image before
│   └── button-128-64-32.png
│
└── build  // Resize the image after
    ├── button.png
    ├── [email protected]
    └── [email protected]
  • Image file name format (src directory files)
button-128-64-32.png
( string-@3xSize-@[email protected] )
#!/bin/sh
# 実行した場所/src へ移動
cd `dirname $0`/src
# 出力ディレクトリの生成
outdir="../build"
mkdir -p $outdir
for file in *\.* ; do
# jpg, png以外を除外する
if [[ $file =~ .*\.[^(jpg|png)] ]] ; then
continue
fi
# ここでファイルを生成する
if [[ $file =~ (.+)-(.+)-(.+)-(.+)\.(jpg|png) ]] ; then
echo "CREATE: ${BASH_REMATCH[1]}@3x.png, ${BASH_REMATCH[1]}@2.png, ${BASH_REMATCH[1]}.png"
sips -Z ${BASH_REMATCH[2]} ${BASH_REMATCH[0]} --out "${outdir}/${BASH_REMATCH[1]}@3x.png" | >/dev/null 2>&1
sips -Z ${BASH_REMATCH[3]} ${BASH_REMATCH[0]} --out "${outdir}/${BASH_REMATCH[1]}@2x.png" | >/dev/null 2>&1
sips -Z ${BASH_REMATCH[4]} ${BASH_REMATCH[0]} --out "${outdir}/${BASH_REMATCH[1]}.png" | >/dev/null 2>&1
else
echo "ファイル名が対応していません: ${file}"
echo "例:button-128-64-32.png (文字列-@3xのサイズ-@2xのサイズ-@1xのサイズ.拡張子)"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment