【问题标题】:Laravel Image Intervention avoid rotationLaravel 图像干预避免旋转
【发布时间】:2021-06-14 04:31:14
【问题描述】:

我正在上传 iPhone 图像 - 由 iPhone 相机垂直拍摄 - 尺寸为 2448x3264 并且因为这个尺寸非常高(?)当我创建 600x360 的拇指时,它会自动旋转到水平。

我尝试了什么都没有成功

  • 更改拇指尺寸
  • 使用fit函数
  • 使用resize函数
  • 使用crop函数
  • 使用upsizeaspectRatio 方法
  • 仅设置 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


【解决方案1】:

如前所述,图像以正确的方向保存,并且在调整大小时,您正在运行 fit() 函数,我可以在该函数上找到 some information on this issue 运行在建议您需要使用的旁边orientate() 合身。

这里有一个例子:

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

我很高兴这有帮助。

【讨论】:

    【解决方案2】:

    根据this github issue,您可能需要在fit() 之前运行orientate()

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

    【讨论】:

      【解决方案3】:
      $img = Image::make($originalFile);
      
      $img->orientate();
      $img->resize(1024, null, function($constraint){
          $constraint->upsize();
          $constraint->aspectRatio();
      });
      $img->save();
      

      【讨论】:

      • 虽然您的代码 sn-p 可能会回答这个问题,但提供有关您的代码 sn-p 为何和/或如何工作的额外上下文可以提高其长期价值。
      猜你喜欢
      • 2013-08-24
      • 2013-07-12
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多