Skip to main content

Fit

Call fit($method, $width, $height) to control how an image fits a box measured in pixels. If you omit the height, Builder uses the width for both dimensions.

$url = sGallery::file($item->src)->fit('max', 500, 300)->getFile();
ModeResult
containFit inside the box while preserving the aspect ratio.
maxFit inside the box without enlarging a smaller image.
fillFit without enlarging, then pad to the requested canvas size.
stretchResize to the exact dimensions; the aspect ratio can change.
cropScale to cover the box and crop the overflow.
fill-maxFit inside the box, allowing enlargement, and pad to the requested canvas size.

Use Crop when you need a specific position or source-pixel coordinates.