Jump to content

Recommended Posts

Posted

Hi everyone! ๐Ÿ‘‹

I'd like to share SquareImages - a simple module that creates perfect square images from any source format.

Born from a real-world need: displaying vertical product images (like Coca-Cola bottles) uniformly in galleries and grids without distortion or awkward sizing.

The Problem

// Traditional methods don't work well for mixed aspect ratios:
$image->width(300);        // Too narrow for vertical images
$image->height(300);       // Too wide
$image->size(300, 300);    // Distorted

The Solution

// One simple method - smart cropping, perfect squares:
$square = $image->square(300);

Key Features

  • ๐ŸŽฏ Smart Cropping - Automatically centers on longer dimension
  • ๐Ÿ“ฆ Format Preservation - Maintains original format (JPG/PNG/GIF)
  • ๐ŸŒ WebP Support - Chain with ->webp() for compression
  • โšก Performance - Fast URL generation
  • ๐Ÿ’พ Automatic Caching - Built on PW's image engine

Quick Example

<div class="product-grid">
    <?php foreach ($page->products as $product): ?>
        <?php $thumb = $product->photo->square(300); ?>
        <img src="<?= $thumb->url ?>" alt="<?= $product->title ?>">
    <?php endforeach; ?>
</div>

Perfect uniform squares, regardless of source dimensions!

API Methods

$image->square(400);           // Main method
$image->squareWidth(500);      // Based on width
$image->squareHeight(600);     // Based on height
$image->getSquareURL(300);     // Direct URL (faster)

// WebP conversion
$image->square(500)->webp();   // 25-65% smaller files

Installation

GitHub: https://github.com/mxmsmnv/SquareImages

cd site/modules/
git clone https://github.com/mxmsmnv/SquareImages.git

Or download ZIP and extract to /site/modules/SquareImages/

Then refresh modules in admin and install.

Use Cases

  • E-commerce product galleries
  • Team member avatars
  • Blog thumbnails
  • Social media previews
  • Instagram-style grids
  • Like 5
  • Thanks 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
ร—
ร—
  • Create New...