Laravel 5.2中无法读取的图像源 - 干预图像

Kal*_*Leb 11 php intervention laravel-5.2

我有一个关于给定图像的大小调整过程的小问题,我正在尝试提交包含输入类型的表单 - >文件< - 我能够上传图片而不调整大小,之后我决定调整大小图像所以我使用以下方法安装了干预图像库:

composer require intervention/image
Run Code Online (Sandbox Code Playgroud)

然后我将库集成到我的Laravel框架中

Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
Run Code Online (Sandbox Code Playgroud)

最后我配置如下

php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Run Code Online (Sandbox Code Playgroud)

我的控制器如下

<?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());

}
}
Run Code Online (Sandbox Code Playgroud)

但不是调整图片大小,而是抛出以下异常

NotReadableException in AbstractDecoder.php line 302:
Image source not readable
Run Code Online (Sandbox Code Playgroud)

bor*_*ast 12

不应该Image::make($file->getRealPath())而不是Image::make('public/uploads/', $file->getRealPath())吗?

Image::make() 似乎没有两个参数,所以这可能是你的问题.

试试这个:

$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());
Run Code Online (Sandbox Code Playgroud)

或者,如果您想在不先移动文件的情况下执行此操作,请尝试以下操作:

$file = Input::file('file');
$img = Image::make($file)
    ->resize(320, 240)
    ->save('public/uploads/', $file->getClientOriginalName());
Run Code Online (Sandbox Code Playgroud)

  • 不,那行不通我已经试过了。``Image::make($file-&gt;getRealPath())`` 或 ``Image::make($file)`` 给出错误为 ``Image source not readable``。它适用于 Laravel 5,但不适用于 L5.2。 (2认同)