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?

Answer
      • 1
    • @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.

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.

  • 15
Reply Report
      • 1
    • 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.
      • 2
    • 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'); ?

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'

);
  • 1
Reply Report

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

  • 0
Reply Report

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);
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions