Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image source not readable in Laravel 5.2 - Intervention Image

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
like image 509
KaldoLeb Avatar asked Aug 12 '16 17:08

KaldoLeb


People also ask

What is intervention Image in laravel?

Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and compose images. The package includes ServiceProviders and Facades for easy Laravel integration.

What is Image intervention?

Intervention Image is an open source PHP image handling and manipulation library. It provides an easier and expressive way to create, edit, and compose images and supports currently the two most common image processing libraries GD Library and Imagick.


2 Answers

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());
like image 180
borfast Avatar answered Oct 13 '22 05:10

borfast


In L5.2 its not directly possible to get image from Input facade. For that we need to first store the image on server and then give path into Image facade to do operations on image.

Code goes likes this:

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

        $destinationPath = public_path('uploads/user');
        $photoname = date("YmdHis");
        $file_extention = '.'.$request->file('picture')->getClientOriginalExtension();
        $photo = $photoname.$file_extention;
        $file_check = $request->file('picture')->move($destinationPath, $photo);

        $thumb_path = $destinationPath.'/thumbnail/'.$photo;

        $new_filePath =  $destinationPath.'/'.$photo;

        $assets_path = url('uploads/user/');

        $img = Image::make($assets_path.'/'.$photo)->fit(100)->save($thumb_path,40);

        $data['picture'] = $photo;           
    }

I was looking for direct solution i.e. as it was possible previously to take image directly from Input facade. If anyone of you have direct solution, show your code here and I'll reward you this bounty. Cheers.

like image 3
Tarunn Avatar answered Oct 13 '22 06:10

Tarunn