artisticre's avatar

Blurry Image on Upload

Here is my code below. It works but the uploaded image is blurry. Can someone help me figure out why and how to fix it?

public function updateProfile(Request $request)
    {
       $user_id = Auth::user()->id;
       $user = User::findOrFail($user_id);
       $user->name = $request->input('name');
       $user->email = $request->input('email');
       $user->address = $request->input('address');
       $user->city = $request->input('city');
       $user->state = $request->input('state');
       $user->zipcode = $request->input('zipcode');
       $user->homephone = $request->input('homephone');
       $user->cellphone = $request->input('cellphone');

       if($request->hasFile('avatar'))
       {

                   $destination = 'uploads/profile/'.$user->avatar;
           if(File::exists($destination)){
               File::delete($destination);
           } 
           $avatar = $request->file('avatar');
           $filename = time() .'.'.$avatar->getClientOriginalExtension();
           Image::make($avatar)->resize(50,50)->save(public_path('/uploads/profile/' . $filename));

           $user = Auth::user();
           $user->avatar = $filename;
      
       }
      
       $user->update();

    
       return redirect()->back()->with('success', $user->name . ' has been updated');

    }
0 likes
4 replies
artisticre's avatar
artisticre
OP
Best Answer
Level 5

I found the issue. ->resize(50,50) is causing it to be blurry. Not sure how to resize it without blurry.

jlrdw's avatar

You should keep the same proportions.

CorvS's avatar

@artisticre You are resizing the image to 50x50px. Do you set a specific size when displaying the image? Everything bigger than the original size makes it look pixelated/blurry.

1 like
Snapey's avatar

store it as a larger size and scale it down when presenting

Please or to participate in this conversation.