干预包不会调整图片laravel 5.5

时间:2018-04-11 15:58:05

标签: php laravel laravel-5 intervention

您好我是laravel的新手,我正在尝试使用干预包从服务器端调整照片大小。图像正在正确上传,但调整大小根本不起作用。

public function upload(Request $request)// store the image 
{             
    $user=Auth::user()->id;
    $this->validate($request, [  
        'title' => 'required',
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',   
    ]);
    $image = $request->file('image');
    $input['image'] = time().'.'.$image->getClientOriginalExtension();
    $input['title'] = $request->title;     
    $input['user_id']=$user; 

    $destinationPath = public_path('/images');
    $img = Image::make($image->getRealPath());
    $img->resize(1024, 200, function ($constraint) {
        $constraint->aspectRatio();
    })->save($destinationPath.'/'.$input['image']);

    $destinationPath = public_path('/images');
    $image->move($destinationPath, $input['image']);

    Photos::create($input);
    // $this->postImage->add($input);

    // $input['image'] = time().'.'.$request->image->getClientOriginalExtension();
    // $request->image->move(public_path('images'), $input['image']);
    // $input['title'] = $request->title;
    // $input['user_id']=$user;     

    // Photos::create($input);

    return back()
    ->with('success','Image Uploaded successfully.')
    ->with('image',$input['image'])
    ->with($user);

} 

请帮助我,我做错了什么?

1 个答案:

答案 0 :(得分:0)

我找到了我的问题的答案我有加密码

    public function upload(Request $request)// store the image 
{             
    $user=Auth::user()->id;
    $this->validate($request, [  
        'title' => 'required',
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',   
    ]);
    $image = $request->file('image');
    $input['image'] = time().'.'.$image->getClientOriginalExtension();
    $input['title'] = $request->title;     
    $input['user_id']=$user; 

    $destinationPath = public_path('/images');
    $img = Image::make($image->getRealPath());
    $img->fit(1024, 1024, function ($constraint) {
        $constraint->upsize();
    })->save($destinationPath.'/'.$input['image']);

    $destinationPath = public_path('/images');

    Photos::create($input);

    return back()
    ->with('success','Image Uploaded successfully.')
    ->with('image',$input['image'])
    ->with($user);

}