Gebs
Gebs

Reputation: 1

Having trouble using intervention/image in laravel-9

I tried to resize my image before uploading but is not working but I am able to upload the image, Here is my Controller:

public function store(Request $request)
{


    $validatedData = $request->validate([
        'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:20480',

       ]);
       $imageFile = $request->file('image');
    
       $name = $imageFile->getClientOriginalName();    
       $path = $request->file('image')->store('images', 'public');
       $resize = Image::make($imageFile)->resize(50, 50)->stream();
       $save = new Gallery;
       
       $save->image = $path;
       $save->status = 1;
       $save->user_id = Auth::id();
       $save->save();

     return redirect('gallery')->with('success', 'Image has been uploaded')->with('image',$name);
}

Upvotes: 0

Views: 543

Answers (1)

Harsh Patel
Harsh Patel

Reputation: 1324

try below example source code. I have done image resize functionality in one of my project with Laravel version 8

<?php
if($request->hasFile('dealimg')){
    $file = $request->File('dealimg');
    $original_name = $file->getClientOriginalName();  
    $file_ext = $file->getClientOriginalExtension();  
    $destinationPath = 'uploads/deals';
    $file_name = "deal".time().uniqid().".".$file_ext;
    // $path = $request->deal_img->store('uploads'); 

    $resize_image = Image::make($file->getRealPath()); //for Resize the Image
    $resize_image->resize(150, 150, function($constraint){ //resize with 150 x 150 ratio
        $constraint->aspectRatio();
    })->save(public_path($destinationPath) . '/' . $file_name); 
    
    $deal_img = $destinationPath."/".$file_name;  
    $request->request->add(['deal_img' => $deal_img]);
}
?>

I hope this one helps to you... see this

Upvotes: 2

Related Questions