LoginSignup
7
5

More than 5 years have passed since last update.

ImageMagickの備忘録

Last updated at Posted at 2018-05-23

参考サイト

http://shumilinux.blogspot.jp/2016/06/imagemagick-mogrify.html
http://technique.sonots.com/?UNIX%2F%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%2F%E5%A4%89%E6%8F%9B%2Fmogrify
http://imagemagick.rulez.jp/

mogrify

縦横比を固定してリサイズ

# 縦横比固定で、幅を128pxにリサイズする
mogrify -resize 128x *.jpg

出力先を指定

-pathオプションを使う。

# リサイズした画像を、一つ上の階層のoutputディレクトリに保存する
mogrify -path ../output -resize 128x *.jpg
$ mogrify -help
...
Image Settings:
...
  -path path           write images to this path on disk

mogrify & convert

クロップ(切り出す)

$ mogrify -crop "100x200+10+20"

矩形で塗りつぶす

$ mogrify  -fill black \
 -draw "rectangle 10,20,110,120"

https://www.imagemagick.org/script/command-line-options.php#draw
http://imagemagick.rulez.jp/archives/744

四角の枠で囲う

http://d.hatena.ne.jp/iww/20120809/imagemagick 参考

# 枠線を書く順番
# 上辺
# 右辺
# 左辺
# 下辺

convert  -stroke red -strokewidth 5 \
 -draw "stroke-linecap square \
line ${lefttop_x},${lefttop_y} ${rightbottom_x},${lefttop_y} \
line ${rightbottom_x},${lefttop_y} ${rightbottom_x},${rightbottom_y} \
line ${lefttop_x},${lefttop_y} ${lefttop_x},${rightbottom_y} \
line ${lefttop_x},${rightbottom_y} ${rightbottom_x},${rightbottom_y} \
" ${src_image_file} ${output_image_file}

その他

findコマンドで見つけたファイルを変換

$ find . -name "*.png" | xargs mogrify -resize 224x

parallelコマンドで並列化

作成中

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5