Search by

ilovejackylee / make-image-square

hiltonlee981

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

Package info

github.com/ilovejackylee/make-image-square

Homepage

Language:Java

pkg:composer/ilovejackylee/make-image-square

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

0.1.1 2026-09-08 06:12 UTC

This package is auto-updated.

Last update: 2026-11-08 00:45:27 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

From JitPack (Maven):

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.github.ilovejackylee</groupId>
  <artifactId>make-image-square</artifactId>
  <version>0.1.1</version>
</dependency>

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