Laravel 图像干预避免旋转

问题描述 投票:0回答:4

我正在上传一张 iPhone 图像(由 iPhone 相机垂直拍摄),尺寸为

2448x3264
,因为这个尺寸太高(?),当我创建
600x360
的拇指时,它会自动旋转到水平位置。

我尝试了什么但没有成功

  • 更改拇指尺寸
  • 使用
    fit
    功能
  • 使用
    resize
    功能
  • 使用
    crop
    功能
  • 使用
    upsize
    aspectRatio
    方法
  • 仅设置
    height
    并在
    width
  • 上使用 null
  • 仅设置
    width
    并在
    height
  • 上使用 null

拇指的最大高度必须为

360
,如果宽度不是
600
我也可以。

$imageResize = Image::make($originalFile);
$imageResize->fit(600, 360, function ($constraint)
{
    $constraint->upsize();
});
$imageResize->save($thumbPath);

我的目标是:

  • 如果原始照片是垂直的,则缩略图是垂直的
  • 如果原始照片是水平的,则缩略图是水平的

我怎样才能实现这个目标?

php laravel intervention
4个回答
19
投票

如前所述,图像正在以正确的方向保存,并且在调整大小时,您正在运行

fit()
函数,我可以在该函数上找到 有关此问题的一些信息 与建议一起运行您需要配合使用
orientate()

这里有一个例子:

$imageResize = Image::make($originalFile);
$imageResize->orientate()
->fit(600, 360, function ($constraint) {
    $constraint->upsize();
})
->save($thumbPath);

我很高兴这有帮助。


7
投票

根据this github issues,您可能需要在

orientate()
之前运行
fit()

$imageResize = Image::make($originalFile)
    ->orientate()
    ->fit(600, 360, function ($constraint) {
        $constraint->upsize();
    })
    ->save($thumbPath);

1
投票
$img = Image::make($originalFile);

$img->orientate();
$img->resize(1024, null, function($constraint){
    $constraint->upsize();
    $constraint->aspectRatio();
});
$img->save();

0
投票

上述解决方案将裁剪图像。为了防止这种情况,您可以稍微更改代码:

$imageResize = Image::make($originalFile);
$imageResize->orientate();
$imageResize->resize(600, null, function ($constraint) {
    $constraint->aspectRatio();
    $constraint->upsize();
})->save($thumbPath);
© www.soinside.com 2019 - 2024. All rights reserved.