Jackaroo Ng Jackaroo Ng - 6 months ago 575
PHP Question

NotReadableException in AbstractDecoder.php line 302: Image source not readable

I trying to follow tutorial about insert image and resize it, but i facing one problem showing image source not readable.

I am using PHP, Laravel 5 framework and mysql. When I run my code i stop on

Image::make


Here is my controller code:

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Requests\FoodRequest;
use App\Http\Controllers\Controller;
use App\Photo;
use Image;
use App\Restaurant;
use Symfony\Component\HttpFoundation\File\UploadedFile;

public function addPhoto($zip, $street, Request $request)
{
$this->validate($request, [
'photo' => 'required|mimes:jpg,jpeg,png,bmp'
]);
$photo = $this->makePhoto($request->file('photo'));
Restaurant::locatedAt($zip, $street)->addPhoto($photo);
}

protected function makePhoto(UploadedFile $file)
{
return Photo::named($file->getClientOriginalName())
->move($file);
}


Here is Photo Code:

public static function named($name)
{
return (new static)->saveAs($name);
}

protected function saveAs($name)
{
$this->name = sprintf("%s-%s", time(), $name);
$this->path = sprintf("%s-%s", $this->baseDir, $this->name);
$this->thumbnail_path = sprintf("%s/tn-%s", $this->baseDir, $this->name);
return $this;
}

public function move(UploadedFile $file)
{
$file->move($this->baseDir, $this->name);
$this->makeThumbnail();
return $this;
}

protected function makeThumbnail()
{
Image::make($this->path)
->fit(200)
->save($this->thumbnail_path);
}

Answer

This is an example from my own code where I write the path to my pics

$destinationpath = 'img/' . $propertyid;
  $frontpage = 'img/' . $propertyid. '/frontpage/' ;
  $gallery =  'img/' . $propertyid. '/gallery/' ;
  $thumbpath = 'img/' .$propertyid .'/thumbnails/';

move the image file to a place at which the Intervention Manipulation code will process the image, change size etc. We will save the results of the processing in their respective folders and then delete this image.

$image->move($destinationpath, $filename );

$dbImg = new Picture;

                    $dbImg->property_id = $propertyid;
                    $dbImg->name = $filename;
                    $dbImg->save();