Command to Center an Image with Blurred Background Edges

This article is a translated version of my original post on Qiita. Original (Japanese): https://qiita.com/segur/items/6fc88aef0db4cec4c90e

Recently, I created an augmented reality (AR) piece like the one described below.

When creating the thumbnail for this piece, I applied the following image transformation!

Image
Input
Output

In essence, when resizing a vertically long image to 1920x1080, the idea was to fill the margins with an enlarged, blurred version of the input image!

Process Overview

Here's the step-by-step process for the above image transformation!

  1. Resize the input image's width to 1920, apply a blur effect, and save it as background.jpg.
  2. Resize the input image's height to 1080 and save it as foreground.jpg.
  3. Use background.jpg as the background, and center foreground.jpg on it to create the final output.

Commands

Here's the command I used! I utilized ImageMagick for the task.

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

Note that the version of ImageMagick used was 7.1.

This image transformation worked perfectly on both Windows and macOS!

In Conclusion

For creating this article, I referred to the following page. Thank you for the insightful information.