繁体   English   中英

使用Laravel Image Intervention调整图像上传大小时出错

[英]Error while resizing image upload with Laravel Image Intervention

我正在使用Laravel Image Intervention来调整表单上图像上传字段的大小。

这是我在上传时收到的错误-我正在代客运行。

Command (Extension) is not available for driver (Gd).

没有Image::make ,以下工作正常

      use Image;
      ...

      $authorID = Auth::user()->id;
      $file = request()->file('ts_image');
      if($file) {
      $file = Image::make($file)->resize(300, 300);

      $fileExtension = $file->extension();
      $unique_name = md5($file. time()).'.'.$fileExtension;
      //
      $fileImg = $file->storeAs('/public/images/' . $authorID, $unique_name);

有任何想法吗? 谢谢!

编辑:

当dd($ file)时,将返回以下内容:

Image {#667 ▼
  #driver: Driver {#668 ▼
    +decoder: Decoder {#669 ▼
      -data: null
    }
    +encoder: Encoder {#670 ▼
      +result: null
      +image: null
      +format: null
      +quality: null
    }
  }
  #core: gd resource @16 ▼
    size: "300x300"
    trueColor: true
  }
  #backups: []
  +encoded: ""
  +mime: "image/jpeg"
  +dirname: "/private/var/tmp"
  +basename: "phpBPRGuD"
  +extension: null
  +filename: "phpBPRGuD"
}

我使用干预将图像保存到数据库中。 我在与laravel合作时,不得不保存不同大小(大,中,小)的图像。 这对我如何工作

      if ($request->hasFile('image')) {
        $image_tmp = Input::file('image');
        if ($image_tmp->isValid()) {

            $extension = $image_tmp->getClientOriginalExtension();
            $filename = rand(111, 99999) . '.' . $extension;
            $large_image_path = 'images/backend_images/products/large/' . $filename;
            $medium_image_path = 'images/backend_images/products/medium/' . $filename;
            $small_image_path = 'images/backend_images/products/small/' . $filename;
            //resize image
            Image::make($image_tmp)->save($large_image_path);
            Image::make($image_tmp)->resize(600, 600)->save($medium_image_path);
            Image::make($image_tmp)->resize(300, 300)->save($small_image_path);
            $product->image = $filename;

        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM