我正在使用Laravel 5.2的干预,我使用Composer和included Intervention\Image\ImageServiceProvider::class
以及'Image' => Intervention\Image\Facades\Image::class in the config/app.php
我还在使用Intervention\Image\ImageManager;
这是我正在尝试处理照片的函数,但是当我提交调用此函数的表单时,我收到此错误消息
BadMethodCallException in Macroable.php line 81:
Method resize does not exist.
功能
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]);
}
答案 0 :(得分:2)
你在文件上调用resize方法,而不是Intervention。
如果您将public class CallRetriever {
// The customer's Account Sid
public static final String ACCOUNT_SID = "AC123";
// Your own Auth Token
public static final String AUTH_TOKEN = "456bef";
public static CallList getAllCalls(String ACCOUNT_SID,String AUTH_TOKEN) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
Account mainAccount = client.getAccount();
retrun mainAccount.getCalls();
}
}
替换为$resizedImg = $file->resize(200,200);
我认为应该有用。
答案 1 :(得分:1)
首先,您应该保存文件,然后使用ImageManager
方法创建make
的实例(对象)。
示例:
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);
}
此外,您可以使用立面Intervention\Image\Facades\Image
代替ImageManager
类。