9

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?

4
  • Show your code and make sure your image location on the server is readable/writable. Commented Jun 12, 2014 at 22:46
  • @WereWolf-TheAlpha I've edited my code. How can I make my image location readable/writable ? Commented Jun 12, 2014 at 23:22
  • Did you check the answer? Commented Jun 13, 2014 at 0:16
  • @WereWolf-TheAlpha I checked your answer. This has solved my problem partially. I have made a composer update, and I finalized my code, taking care to put your suggestion. Check my comment of your answer. Commented Jun 13, 2014 at 7:33

4 Answers 4

14

Change this:

$file = Image::make('url_Avatar');

To this:

$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);

Read more about file on Laravel documentation.

Sign up to request clarification or add additional context in comments.

4 Comments

Indeed, I change the line you suggest me into $file = Input::file('url_Avatar');. I have also change the line $file= Image::make($image->getRealPath())->resize('200','200')->save('upload/'.$filename); into Image::make($file->getRealPath())->resize('200','200')->save($filename);. It works well. Thank you for the help, your answer guided me to make this feature.
I have a similar problem. I also edit my code as pointed out by you but it still gives me the same error message. Can you please have a look at the link and help me out?
I am also having the same problem. I need to make image from url. Using Input::file() we can make image from input type file only. But in my case input is url. So How can I?
Have you tried $image = Image::make('http://someurl.com/image.png')->save('/path/ImageName.png'); ?
2

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'

);

Comments

0

if you use a sub-folder in your public path, use chmod to change the permission on that folder e.g cd public; chmod -Rv 755 public/{your_path_name};

Run

man chmod;

for more details

Comments

0

this in solution

$filename = str_slug($products->name)."-0.jpg";
$filename_fb = 'fb-'.$filename;
$filename_tw = 'tw-'.$filename;

$img = Image::make($_FILES['photo']['tmp_name']);
// resize image
$img->resize(800, 400);
// save image
$img->save($path.'/'.$filename);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.