Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intervention \ Image \ Exception \ NotReadableException using laravel 4

I'm using laravel 4 and I installed the Intervention Image package. When I'm using it in my code whith method ->resize, ->move etc etc etc... I have this error:

Intervention \ Image \ Exception \ NotReadableException

Image source not readable

open: /Applications/MAMP/htdocs/myNameProject/vendor/intervention/image/src/Intervention/Image/AbstractSource.php

        break;

        case $this->isFilePath():
            return $this->initFromPath($this->data);
            break;

        default:
            throw new Exception\NotReadableException("Image source not readable");
            break;
    }

I'm also using MAMP and Sublime Text 3 on MAC OS if it could help you.

This is my code in my controller:

public function upload() {

//***** UPLOAD FILE (on server it's an image but an Url in Database *****//

// get the input file
$file = Image::make('url_Avatar');

//set a register path to the uploaded file
$destinationPath = public_path().'upload/';

//have client extension loaded file and set a random name to the uploaded file, produce a random string of length 32 made up of alphanumeric characters [a-zA-z0-9]
$filename = $destinationPath . '' . str_random(32) . '.' . $file->getClientOriginalExtension();
//$file->move($destinationPath,$filename);

//set $file in order to resize the format and save as an url in database
$file= Image::make($image->getRealPath())->resize('200','200')->save('upload/'.$filename);

//*****VALIDATORS INPUTS and RULES*****
$inputs = Input::all();
$rules = array(
'pseudo' => 'required|between:1,64|unique:profile,pseudo',
//urlAvatar is an url in database but we register as an image on the server
'url_Avatar' => 'required|image|min:1',
);

(I don't show you the redirect of my view, but it's worked fine for this section of my controller)

here is my form code (using blade laravel template):

@extends('layout.default')
@section('title')
Name Of My Project - EditProfile
@stop

@section('content')
{{Form::open(array('url'=>'uploadAvatar','files' => true))}}

<p>
{{Form::label('pseudo','pseudo (*): ')}}
{{Form::text('pseudo',Input::old('nom'))}}
</p>
@if ($errors->has('pseudo'))
<p class='error'> {{ $errors->first('pseudo')}}</p>
@endif
<br>
<br>

<p>
{{Form::label('url_Avatar','Avatar: ')}}
{{Form::file('url_Avatar',Input::old('Url_Avatar'))}}
</p>
@if ($errors->has('url_Avatar'))
<p class='error'> {{ $errors->first('url_Avatar')}}</p>
@endif
<br>
<br>

<p>
{{Form::submit('Validate your avatar')}}
</p>

{{Form::close()}}
@stop

Of course I have installed Intervention Image package following the official website image.intervention.io/getting_started/installation (url).

How can I make my file "readable"? or resolve this error?

like image 772
french_dev Avatar asked Jun 12 '14 22:06

french_dev


1 Answers

I have the same problem. When I change image driver everything works fine.

Try to change image driver from app/config/packages/intervention/image/config.php from GD to Imagick

If you cant find config file try to run commands below:

Publish configuration in Laravel 5

$ php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"

Publish configuration in Laravel 4

$ php artisan config:publish intervention/image

Example content from config file:

return array(

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    |
    | Intervention Image supports "GD Library" and "Imagick" to process images
    | internally. You may choose one of them according to your PHP
    | configuration. By default PHP's "GD Library" implementation is used.
    |
    | Supported: "gd", "imagick"
    |
    */

    'driver' => 'imagick'

);
like image 133
nikssa23 Avatar answered Oct 09 '22 11:10

nikssa23