2017-05-29 76 views
0

我正在使用Laravel 5.4學習Intervention Image軟件包。我的圖像存儲在我的公共/圖像文件夾中。Laravel 5.4 Intevention圖像不可讀取圖像可讀時出現異常

我根據介入頁面上的說明安裝了Image:爲我的composer.json文件添加了干預,運行了composer update,更新了我的config/app文件,並運行了composer dump-autoload。

  • 當作爲圖像的圖像顯示裝置(在下面的代碼 塊的printf語句)直接訪問。

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

有誰看到,如果我做錯事的代碼或可能已經錯過了在安裝了一步?

<?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 
+0

如果您在laravel中使用public_path helper函數,該怎麼辦? EG: $ img = Image :: make(public_path('images/j6.jpg')) - > resize(300,200); – Crawdingle

回答

0

您需要提供您的filesystem.Judging從圖像文件的完整路徑您的圖片標記,圖片應位於您的webroot中的images文件夾中。你可以這樣做。

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

謝謝 - 是的,就是這樣。它讓我困惑,圖像源是相對於web根目錄的,但Image方法需要完整的路徑。謝謝。 – JohanTux