在Laravel 5.2中无法读取图像源-干预图像 [英] Image source not readable in Laravel 5.2 - Intervention Image

查看:132
本文介绍了在Laravel 5.2中无法读取图像源-干预图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于给定图像的大小调整过程,我有一个小问题,我正在尝试提交包含输入类型的表单-> 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中无法读取图像源-干预图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆