make_image_square

Tiny helper that turns any image size into a 1:1 layout plan: square canvas size plus left/right/top/bottom padding so you can fit without cropping.

Useful when you need the math for letterboxing / pillarboxing before you draw to a canvas, generate CSS object-fit-style boxes, or prep assets for Instagram and profile photos.

Install

def deps do
[
{:make_image_square, "~> 0.1.0"}
]
end

Usage

# 1200×800 landscape → 1200×1200 with top/bottom pads
layout = MakeImageSquare.make_image_square(1200, 800)
# canvas 1200, pad_top 200, pad_bottom 200
# Force a specific square edge (e.g. 1080 for feed posts)
ig = MakeImageSquare.make_image_square(1200, 800, canvas_size: 1080)
# Padding-only helper
pads = MakeImageSquare.square_padding(800, 1200)

Modes

ModeBehavior
:fit (default)Entire image visible; empty bands become padding
:fillImage covers the square; caller is expected to crop overflow

Notes

License

MIT