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)