Skip to content

Instantly share code, notes, and snippets.

@hata6502
Last active April 28, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hata6502/dc46fd6108301ed9106da67db6768ec9 to your computer and use it in GitHub Desktop.
Save hata6502/dc46fd6108301ed9106da67db6768ec9 to your computer and use it in GitHub Desktop.
指定の比率で画像をトリミングします。ImageMagick を使って 16:9 でトリミングするのが面倒だったのでシェルスクリプトにしました。
#!/bin/bash
if [ $# -lt 6 ]; then
echo "Usage: `basename $0` (source path) (width rate) (height rate) (X offset) (y offset) (destination path) [(options)]"
exit 1
fi
width=`identify -format "%w" $1`
height=$((width*$3/$2))
convert "$1" ${@:7} -crop ${width}x${height}+$4+$5 "$6"
@hata6502
Copy link
Author

hata6502 commented Apr 20, 2019

環境要件: ImageMagick が必要です。

使い方: trimrate (元ファイル) (幅比率) (高さ比率) (横オフセット) (縦オフセット) (保存先パス) [(追加の ImageMagick オプション)]
(例) trimrate src.jpg 16 9 0 0 dest.jpg -gravity center

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment