Search by

ilovejackylee / make-image-square

Compute square canvas size and letterbox padding so an image fits 1:1 without cropping.

Maintainers

Package info

github.com/ilovejackylee/make-image-square

Homepage

pkg:composer/ilovejackylee/make-image-square

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-09-07 08:39 UTC

This package is auto-updated.

Last update: 2026-09-07 10:19:54 UTC


README

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

composer require ilovejackylee/make-image-square

Usage

use MakeImageSquare\Layout;

// 1200×800 landscape → 1200×1200 with top/bottom pads
$layout = Layout::makeImageSquare(1200, 800);
// canvas 1200, padTop 200, padBottom 200

// Force a specific square edge (e.g. 1080 for feed posts)
$ig = Layout::makeImageSquare(1200, 800, Layout::MODE_FIT, 1080);

// Padding-only helper
$pads = Layout::squarePadding(800, 1200); // portrait → pad left/right

Modes

Mode Behavior
fit (default) Entire image visible; empty bands become padding
fill Image covers the square; caller is expected to crop overflow

Notes

  • This package only returns numbers. It does not decode or rewrite image files.
  • Prefer not to wire up GD or Imagick yourself? There is a no-signup 1:1 photo tool that pads, blurs the frame, or crops in the browser.

License

MIT