メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Trim::resizeTrim

Resize the image with keeping ratio and trimming 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. 0 means the original width or height.

Arguments​

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

Crop position​

$cpKept part
tTop center
rtTop right
lMiddle left
mCenter
rMiddle right
bBottom center
lbMiddle left (same as l)
rbBottom center (same as b)
lt or any other valueTop left
メモ

In the current implementation lb and rb do not crop at the bottom corners: they behave like l and b.

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();