Reputation: 259
I am using Intervention with Laravel 5.2, I have installed it using Composer and included Intervention\Image\ImageServiceProvider::class
and 'Image' => Intervention\Image\Facades\Image::class in the config/app.php
I have also added the use statement to the Controller where I am using it use Intervention\Image\ImageManager;
Here is my function where I am trying to process the photo, but when I submit the form that calls this function I get this error message
BadMethodCallException in Macroable.php line 81:
Method resize does not exist.
Function
public function postAvatarUpload(Request $request)
{
$this->validate($request, [
'image' => 'required|image|max:3000|mimes:jpeg,jpg,png',
]);
$user = Auth::user();
$usersname = $user->username;
$file = $request->file('image');
$resizedImg = $file->resize(200,200);
$ext = $file->getClientOriginalExtension();
$filename = $usersname . '.' . $ext;
if (Storage::disk('public')->has($usersname)) {
Storage::delete($usersname);
}
Storage::disk('public')->put($filename, File::get($resizedImg));
$avatarPath = Storage::url($filename);
Auth::user()->update([
'image' => $avatarPath,
]);
return redirect()->route('profile.index',
['username' => Auth::user()->username]);
}
Upvotes: 0
Views: 3249
Reputation: 198
First you should save the file and then create instance (object) of ImageManager
using the method make
.
Example:
public function upload(Request $request)
{
$file = $request->file('image');
$path = 'path/to';
$fileName = 'example_name.' . $file->extension();
$file->move($path, $fileName);
$image = ImageManager::make($path . DIRECTORY_SEPARATOR . $fileName);
}
Also, you may use the facade Intervention\Image\Facades\Image
instead of ImageManager
class.
Upvotes: 2
Reputation: 91
You're calling the resize method on the file, not Intervention.
Should work if you replace $resizedImg = $file->resize(200,200);
with $resizedImg = Image::make($file)->resize(200,200);
I think.
Upvotes: 2