【问题标题】:image source not readable using image intervention laravel 7使用图像干预laravel 7无法读取图像源
【发布时间】:2020-08-12 09:00:48
【问题描述】:

我正在尝试从 chrome 手机中的相机上传照片,但出现错误图像源不可读。

当我尝试在 android 中从相机上传图像时出现错误,但是当我尝试使用 iphone 从相机上传图像时,图像已成功上传。我的代码是这样的,我在 Laravel 7 中使用图像干预

    $image = $request->file('foto');
    $image_name = str_replace(' ','_',$request->judul).'_'.time() . '.' . $image->getClientOriginalExtension();
    $destinationPath = public_path('/assets/img/galang_dana');

    $resize_image = Image::make($image->getRealPath());
    $resize_image->fit(800, 500, function ($constraint) {
    $constraint->upsize();
    })->save($destinationPath . '/' . $image_name);

     $destinationPath = public_path('/assets/img/galang_dana/resize');
     $image = $image->move($destinationPath, $image_name);

【问题讨论】:

    标签: laravel image upload


    【解决方案1】:

    您可以使用此代码将照片保存到目的地并同时调整照片大小。

    $image = Image::make(public_path('assets/img/galang_dana/resize' . time() . "." . 
    request()->foto->getClientOriginalExtension()))->resize(800, 500);
    $image->save();
    

    您正在使用 fit 方法裁剪照片,但 resize 方法将调整照片大小而不裁剪照片。 它一直对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2016-12-19
      • 2017-06-09
      • 2020-04-29
      • 2017-05-21
      • 2021-03-14
      • 1970-01-01
      相关资源
      最近更新 更多