Open2

shell

KazuhoKazuho

LINE Botの制作でイメージマップを生成するときに、複数サイズの画像が必要だったので。
LINEの仕様で、書き出した画像は拡張子なし形式が正だが、単純なリサイズをする場合は"${D}/${s}.png"とする。

#!/bin/zsh

resize() {
  P=$1
  D=$(dirname $P)
  sizes=(240 300 460 700 1040)
  for s in $sizes; do
    convert ${P} -strip -unsharp 0x0.75+0.5+0 -resize ${s}x "${D}/${s}" &
  done
  wait
}

DIR=${1%/} #remove the trailing slash
if [ -d $DIR ]; then
  for f in $DIR/*.png; do
    resize $f
  done
else
  echo "Usage: ./resize-png.zsh <dir>"
  echo "  <dir> is a directory containing png files"
  exit 1
fi