Skip to main content
Version: Fegg 5.x

Trim::resizeTrim

Resize the image keeping its ratio and cut off the overflow (like object-fit: cover)

Description​

public void Trim::resizeTrim( int $w, int $h, string $cp )

The output is exactly $w x $h. The image is scaled to cover the whole area, keeping its aspect ratio, and the overflow is cut off. $cp decides which part of the image is kept.

Arguments​

NameData typeDefaultRemarks
$wintOutput width / 0: original width
$hintOutput height / 0: original height
$cpstringCrop position (see below)

Crop position​

The positions are listed in Trim::POSITIONS.

$cpKept part
ltTop left
tTop center
rtTop right
lMiddle left
mCenter
rMiddle right
lbBottom left
bBottom center
rbBottom right

Any other value is lt.

Example​

Controller
use Fegg\Tool\Trim;

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

$trim->resizeTrim(300, 300, 'm');
$trim->create();