LoginSignup
2
1

画像を中央に配置して余白にぼかしを入れるコマンド

Posted at

先日、以下のようなAR作品を作りました。

この作品のサムネイルを作るときに、以下のような画像変換をしました!

画像
入力
出力

つまり、縦長画像を1920x1080にリサイズするときに、入力画像をぼかして拡大したもので余白を埋めたいという状況です!

処理内容

上記の画像変換の処理手順を書き出すとこんな感じです!

  1. 入力画像のwidthを1920にリサイズして、ぼかし処理をかけたものを background.jpg として出力する。
  2. 入力画像のheightを1080にリサイズしたものを foreground.jpg として出力する。
  3. background.jpg を背景として、 foreground.jpg を中央に合成して出力する。

コマンド

完成したコマンドがこちらです!ImageMagickを使ってみました!

magick convert input.jpg -resize 1920x -blur 0x8 -gravity north -extent 1920x1080 background.jpg
magick convert input.jpg -resize x1080 foreground.jpg
magick convert background.jpg foreground.jpg -gravity center -composite output.jpg

なお、ImageMagickのバージョンは7.1です。

WindowsでもmacOSでも無事に画像変換できました!

さいごに

本記事作成にあたり、以下のページを参考にしました。ありがとうございました。

2
1
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
2
1