Laravel 5.4干预图像不可读图像可读时的例外情况

时间:2017-05-29 17:31:23

标签: php laravel-5 intervention

我正在使用Laravel 5.4了解干预图像包。我的公共/图像文件夹中存有图像。

我根据干预页面上的说明安装了Image:添加了对我的composer.json文件的干预,运行了composer update,更新了我的config / app文件,并运行了composer dump-autoload。

  • 直接作为图像访问时(代码中的printf语句) 在下面阻止)图像显示。

  • 使用make方法,我得到一个NotReadableException AbstractDecoder.php。

有人看到我在代码中做错了什么或可能错过了安装步骤吗?

<?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');
    }
}

这是&#34; printf&#34;之后页面上的错误块的主角。图像:

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

1 个答案:

答案 0 :(得分:0)

您需要在文件系统中提供图像文件的完整路径。从图像标记中判断,图像应位于您的webroot的images文件夹中。你可以这样做。

$imagePath = public_path('images/j6.jpg');
$img = Image::make($imagePath)->resize(300, 200);