ojwando's avatar

Image Intervention usage

Kindly show me how to resize including image intervention in this code. ''' public function store(Request $request)

{

    $validatedData = $this->validate($request,[

        'title'=>'required|min:3|max:150',
         'tag'=>'nullable',
        'body'=>'required',
        'slug'          => 'required|min:3|max:255|unique:posts',
        'image'=> 'max:1999',

    ]);
    $validatedData['slug'] = Str::slug($validatedData['slug'], '-');
    if($request->hasFile('image')) {
        // Get filename with extension           
         $filenameWithExt = $request->file('image')->getClientOriginalName();
        // Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);            
       // Get just ext
        $extension = $request->file('image')->getClientOriginalExtension();
        //Filename to store
        $fileNameToStore = $filename.'_'.time().'.'.$extension;                       
      // Upload Image
        $path = $request->file('image')-> storeAs('public/images', $fileNameToStore);
        
    } else {
        $fileNameToStore = 'noimage.jpg';
    }

    $posts = new Post;
    $posts->title = $request->input('title');
    $posts->tag = $request->input('tag');
    $posts->body = $request->input('body');
    $str = strtolower($request->title);
    $posts->image = $fileNameToStore;
    
    $posts->slug = $validatedData['slug'];
    $posts->save();
    return redirect()->route('posts.index');

}

'''

0 likes
2 replies
ojwando's avatar

@martinbean I don't know where to place ''' $img = Image::make('public/foo.jpg');

// resize image to fixed size $img->resize(300, 200); '''

Please or to participate in this conversation.