web-dev-qa-db-fra.com

Intervention\Image\Exception\NotReadableException utilisant Laravel 4

J'utilise laravel 4 et j'ai installé le paquet Intervention Image . Quand je l'utilise dans mon code avec méthode -> redimensionner, -> déplacer etc etc etc ... j'ai cette erreur:

Intervention \ Image \ Exception \ NotReadableException

Source de l'image non lisible

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;
    }

J'utilise également MAMP et Sublime Text 3 sur MAC OS si cela peut vous aider.

Ceci est mon code dans mon contrôleur:

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',
);

(Je ne vous montre pas la redirection de ma vue, mais cela a bien fonctionné pour cette section de mon contrôleur)

voici mon code de formulaire (en utilisant le modèle de lame laravel):

@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

Bien sûr, j'ai installé le paquet Image d'intervention suivant le site officiel image.intervention.io/getting_started/installation (url).

Comment puis-je rendre mon fichier "lisible"? ou résoudre cette erreur?

8
french_dev

Change ça:

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

Pour ça:

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

En savoir plus sur fichier sur Laravel documentation .

15
The Alpha

J'ai le même problème. Quand je change de pilote d'image, tout fonctionne bien.

Essayez de changer le pilote d’image de app/config/packages/intervention/image/config.php de Gd à Imagick

Si vous ne trouvez pas le fichier de configuration, essayez d’exécuter les commandes ci-dessous:

Publier la configuration dans Laravel 5

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

Publier la configuration dans Laravel 4

$ php artisan config: publie intervention/image

Exemple de contenu du fichier de configuration:

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
nikssa23

ceci en 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
Mas Hary

si vous utilisez un sous-dossier dans votre chemin public, utilisez chmod pour modifier l’autorisation sur ce dossier, par exemple cd public; chmod -Rv 755 public/{your_path_name};.

Courir

man chmod;

pour plus de détails

0
Jon Awoyele