Skip to main content
Version: Fegg 5.x

Trim::resizeFill

Resize the image keeping its ratio and fill the empty area (like object-fit: contain)

Description​

public void Trim::resizeFill( int $w, int $h )

The output is exactly $w x $h. The image is scaled down to fit in it, keeping its aspect ratio, and placed in the center. The empty area is transparent for PNG output (and for GIF output from a PNG or GIF source), white otherwise. Images smaller than the specified size are not enlarged.

Arguments​

NameData typeDefaultRemarks
$wintOutput width / 0: original width
$hintOutput height / 0: original height

Example​

Controller
use Fegg\Tool\Trim;

$trim = new Trim();
$trim->setImage('path/to/image.png', 'path/to/converted.png');

$trim->resizeFill(300, 300);
$trim->create();