Takazudo Modular Docs

Type to search...

to open search from anywhere

l-format-images-square

Convert images to square format with centered placement, white background, and padding using ImageMagick.

Format Images to Square

Converts images to square format with centered placement, white background, and consistent padding.

Usage

/format-images-square <input-dir> <output-dir> [padding-percent]

What it does

  1. Analyzes all images to find maximum height
  2. Creates square canvas (max_height x max_height)
  3. Adds white background
  4. Resizes each image to fit with padding on all edges
  5. Centers images on canvas while preserving aspect ratio
  6. Outputs processed images to specified directory

Parameters

  • input-dir: Directory containing source images
  • output-dir: Directory for processed output
  • padding-percent: Optional padding percentage (default: 5%)

Example

Input images:

  • image1.jpg (1200 x 800)
  • image2.jpg (600 x 1200)
  • image3.jpg (1200 x 1169)

Process:

  • Max height detected: 1200px
  • Canvas size: 1200 x 1200
  • Padding: 5% (60px each edge)
  • Available space: 1080 x 1080

Output:

  • All images are 1200 x 1200 square
  • Original images centered with aspect ratio preserved
  • 5% white padding on all edges

Technical Details

Uses ImageMagick (convert/magick command):

convert image.jpg \
  -resize {available}x{available} \
  -background white \
  -gravity center \
  -extent {canvas}x{canvas} \
  output.jpg

Configuration

Default values:

  • Padding: 5% on each edge (top, right, bottom, left)
  • Background: white
  • Gravity: center
  • Resize method: best fit (maintains aspect ratio)

Notes

  • Requires ImageMagick installed
  • Works with JPG, PNG, and other common formats
  • Canvas size determined by tallest image
  • All output images have identical dimensions
  • Ideal for product galleries, thumbnails, social media posts

Arguments

$ARGUMENTS - Input directory, output directory, and optional padding percentage