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

时间:2018-11-11 20:09:07

标签: php laravel php-gd

我正在使用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"
}

1 个答案:

答案 0 :(得分:2)

我进行了干预,将图像保存到数据库中。我在与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;

        }
    }