Search code examples
laravelbase64image-resizing

Call to a member function move() on string Larael base64 encoded


I'm getting photo from Android phone using API and base64encoded format. After getting photo i must to resize it. But i'm getting error. Please help to solve it.

$image = $request->photo;  // my base64 encoded
$image = str_replace('data:image/jpg;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imagename = 'prsn-'.time().'.jpg';

$destinationPath = public_path('/thumbnail');
$img = Image::make($image);
$img->resize(150, 150, function ($constraint) 
{
    $constraint->aspectRatio();
  })->save($destinationPath.'/'.$imagename);
 $destinationPath = storage_path('local');
 $image->move($destinationPath, $imagename);  /***  <<<<<<< getting error on this line ***/

$input = $request->all();
$input['photo'] = $imagename;
Contact::create($input);

Solution

  • Problem is solved using belowed code

     $image = $request->photo;  // my base64 encoded
     $image = str_replace('data:image/jpg;base64,', '', $image);
     $image = str_replace(' ', '+', $image);
     $imagename = 'prsn-'.time().'.jpg';
     
     $destinationPath = public_path('/thumbnail');
     $img = Image::make($image);
     $img->resize(150, 150, function ($constraint) 
      {
         $constraint->aspectRatio();
      })->save($destinationPath.'/'.$imagename);
      $destinationPath = public_path('/images');
      Image::make($image)->save($destinationPath.'/'.$imagename);
    
      $input = $request->all();
      $input['photo'] = $imagename;
      Contact::create($input);
    

    Thanks for all who want to help, special thank to: porloscerros-Ψ for advice and suggestion