首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel5.4当图像可读时不可读的异常

Laravel5.4当图像可读时不可读的异常
EN

Stack Overflow用户
提问于 2017-05-29 17:31:23
回答 1查看 1.1K关注 0票数 1

我正在学习Laravel5.4的干预图像包。我在“公共/图像”文件夹中存储了一个图像。

我按照干预页面上的说明安装了图像:将干预添加到我的composer.json文件、composer.json更新、更新了我的config/app文件以及composer.json autoload。

  • 当作为图像直接访问时(下面代码块中的printf语句)显示图像。
  • 使用make方法,我在AbstractDecoder.php中得到了一个AbstractDecoder.php。

是否有人看到我在代码中做错了什么,或者可能在安装过程中错过了一个步骤?

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;

class TestController extends Controller
{
    public function imagetest()
    {
        printf('<img src="/images/j6.jpg">'); //correctly displays image on page

        $img = Image::make("/images/j6.jpg")->resize(300, 200); //throws the error
        return $img->response('jpg');
    }
}

下面是"printf“图像后面页面上的错误块的牵头部分:

代码语言:javascript
复制
Whoops, looks like something went wrong.

1/1
NotReadableException in AbstractDecoder.php line 339:
Image source not readable
in AbstractDecoder.php line 339
at AbstractDecoder->init('/images/j6.jpg') in AbstractDriver.php line 64
at AbstractDriver->init('/images/j6.jpg') in ImageManager.php line 50
at ImageManager->make('/images/j6.jpg') in Facade.php line 221
at Facade::__callStatic('make', array('/images/j6.jpg')) in TestController.php line 14
at TestController->imagetest()
at call_user_func_array(array(object(TestController), 'imagetest'), array()) in Controller.php line 55
at Controller->callAction('imagetest', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(TestController), 'imagetest') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-29 18:33:04

您需要从图像标记中提供filesystem.Judging中图像文件的完整路径,图像应该位于webroot的images文件夹中。你可以做到这一点。

代码语言:javascript
复制
$imagePath = public_path('images/j6.jpg');
$img = Image::make($imagePath)->resize(300, 200);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44247807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档