まあ、彼のヒントの@Anton
のおかげで、私は私の問題を解決するためにこれをした:
画像は横長方形、縦長の長方形または正方形です。
は、私はすべての状況に次の行のコードを書いて、それが私の場合のために素晴らしい作品
$img = Image::make($image->getRealPath());
$width = $img->width();
$height = $img->height();
/*
* canvas
*/
$dimension = 2362;
$vertical = (($width < $height) ? true : false);
$horizontal = (($width > $height) ? true : false);
$square = (($width = $height) ? true : false);
if ($vertical) {
$top = $bottom = 245;
$newHeight = ($dimension) - ($bottom + $top);
$img->resize(null, $newHeight, function ($constraint) {
$constraint->aspectRatio();
});
} else if ($horizontal) {
$right = $left = 245;
$newWidth = ($dimension) - ($right + $left);
$img->resize($newWidth, null, function ($constraint) {
$constraint->aspectRatio();
});
} else if ($square) {
$right = $left = 245;
$newWidth = ($dimension) - ($left + $right);
$img->resize($newWidth, null, function ($constraint) {
$constraint->aspectRatio();
});
}
$img->resizeCanvas($dimension, $dimension, 'center', false, '#ffffff');
$img->save(public_path("storage/{$token}/{$origFilename}"));
/*
* canvas
*/
http://image.intervention.io/api/resizeCanvas – mkaatman