I have a small problem concerning the resizing process of a given image, I am trying to submit a form containing an input type -->file<-- I was able to upload a picture without resizing it, after that I decided to resize that image so I installed the Intervention Image Library using:
composer require intervention/image
then I integrated the library into my Laravel framework
Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
and finally I configured it like following
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
my controller is like the following
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Image;
class ProjectController extends Controller{
public function project(Request $request){
$file = Input::file('file');
$fileName = time().'-'.$file->getClientOriginalName();
$file -> move('uploads', $fileName);
$img=Image::make('public/uploads/', $file->getRealPath())->resize(320, 240)->save('public/uploads/',$file->getClientOriginalName());
}
}
but instead of resizing the pic the following exception is throwed
NotReadableException in AbstractDecoder.php line 302:
Image source not readable
Shouldn't it be Image::make($file->getRealPath())
instead of Image::make('public/uploads/', $file->getRealPath())
?
Image::make()
doesn't seem to take two arguments, so that could be your problem.
Try this:
$file = Input::file('file');
$fileName = time() . '-' . $file->getClientOriginalName();
$file->move('uploads', $fileName);
$img = Image::make($file->getRealPath())
->resize(320, 240)
->save('public/uploads/', $file->getClientOriginalName());
Or if you want to do it without moving the file first, try this:
$file = Input::file('file');
$img = Image::make($file)
->resize(320, 240)
->save('public/uploads/', $file->getClientOriginalName());