【问题标题】:Laravel 5.4 Intevention Image Not Readable Exception when the image is readableLaravel 5.4 Intevention Image Not Readable 图像可读时出现异常
【发布时间】:2017-05-29 17:31:23
【问题描述】:

我正在学习 Laravel 5.4 的干预图像包。我的公共/图像文件夹中存储了一张图像。

我根据干预页面上的说明安装了 Image:向我的 composer.json 文件添加干预,运行 composer update,更新我的配置/应用程序文件,并运行 composer dump-autoload。

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

  • 使用 make 方法,我在 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');
    }
}

这里是“printf”图像之后页面上的错误块的引导:

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

【问题讨论】:

  • 如果你在 laravel 中使用 public_path 辅助函数会怎样。例如:$img = Image::make(public_path('images/j6.jpg'))->resize(300, 200);

标签: php laravel-5 intervention


【解决方案1】:

你需要在你的文件系统中提供图片文件的完整路径。从你的图片标签来看,图片应该在你的webroot的images文件夹中。你可以这样做。

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

【讨论】:

  • 谢谢 - 是的,就是这样。让我感到困惑的是,图像源是相对于 Web 根目录的,但 Image 方法需要完整路径。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-05-05
  • 2018-04-15
  • 2018-05-02
  • 2012-05-13
  • 2018-04-15
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
相关资源
最近更新 更多