问题描述
关于给定图像的大小调整过程,我有一个小问题,我正在尝试提交包含输入类型的表单-> file<-在决定不调整大小的情况下,我能够上传图片调整图像的大小,因此我使用以下命令安装了干预图像库:
I have a small problem concerning the resizing process of a given image, I am trying to submit a form containing an input type -->file<-- I was able to upload a picture without resizing it, after that I decided to resize that image so I installed the Intervention Image Library using:
composer require intervention/image
然后将库集成到我的Laravel框架中
then I integrated the library into my Laravel framework
Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
最后我像下面这样配置
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
我的控制器如下所示
<?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());
}
}
但未调整图片大小,而是引发了以下异常
but instead of resizing the pic the following exception is throwed
NotReadableException in AbstractDecoder.php line 302:
Image source not readable
推荐答案
不是Image::make($file->getRealPath())
而不是Image::make('public/uploads/', $file->getRealPath())
吗?
Image::make()
似乎没有两个参数,所以这可能是您的问题
Image::make()
doesn't seem to take two arguments, so that could be your problem.
尝试一下:
$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());
或者,如果您不想在不先移动文件的情况下进行操作,请尝试以下操作:
Or if you want to do it without moving the file first, try this:
$file = Input::file('file');
$img = Image::make($file)
->resize(320, 240)
->save('public/uploads/', $file->getClientOriginalName());
这篇关于在Laravel 5.2中无法读取图像源-干预图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!