Changes

Jump to: navigation, search

How To Batch Letterbox Images with Imagemagick

1,012 bytes added, 13:15, 31 January 2022
Created page with "=Letterboxing= To be able to run the command below you'll need to install a utility called [https://imagemagick.org/index.php ImageMagick]. This command will take an input ima..."
=Letterboxing=
To be able to run the command below you'll need to install a utility called [https://imagemagick.org/index.php ImageMagick].
This command will take an input image and letterbox it into a 4:3 aspect ratio with black borders
<pre>magick INPUT.JPG -set option:wd "%[fx:(4/3)>(w/h)?(4/3*h):w]" -set option:ht "%[fx:(4/3)>(w/h)?h:(w/(4/3))]" -gravity center -background black -extent "%[wd]x%[ht]" OUTPUT.JPG</pre>

=Batch Letterboxing at the Windows Command Line=
This command will letterbox all JPG files in the active directory into 4:3 aspect ratio images with black borders
<pre>for %i in (*.jpg) do magick %i -set option:wd "%[fx:(4/3)>(w/h)?(4/3*h):w]" -set option:ht "%[fx:(4/3)>(w/h)?h:(w/(4/3))]" -gravity center -background black -extent "%[wd]x%[ht]" %i</pre>

=References=
*https://stackoverflow.com/questions/56672830/how-to-resize-an-image-in-imagemagick-but-keep-an-aspect-ratio-constant
*https://www.windows-commandline.com/windows-for-loop-examples/
*https://imagemagick.org/index.php

Navigation menu