Decoder.php中的laravel NotReadableException - 无法从文件中读取图像

时间:2016-12-31 20:31:14

标签: php laravel-5

所以我收到了这个错误。在搜索互联网后,问题可能出现在post_upload_sizepost_size上,但事实并非如此。

我上传较大的图片,工作正常,然后这个1.5MB的图像不起作用。这是随机的。它适用于某些图像,但不适用于所有图像。这是完整的输出。

糟糕,看起来出了问题:

  

在Decoder.php第46行中的1/1 NotReadableException:无法从文件中读取图像(/ tmp / phpVpVQeP)。

in Decoder.php line 46
at Decoder->initFromPath('/tmp/phpVpVQeP') in AbstractDecoder.php line 293
at AbstractDecoder->init('/tmp/phpVpVQeP') in AbstractDriver.php line 64
at AbstractDriver->init('/tmp/phpVpVQeP') in ImageManager.php line 50
at ImageManager->make('/tmp/phpVpVQeP') in Facade.php line 215
at Facade::__callStatic('make', array('/tmp/phpVpVQeP')) in ProfileController.php line 251
at Image::make('/tmp/phpVpVQeP') in ProfileController.php line 251
at ProfileController->sendProfile(object(Request), 'klaughlin')
at call_user_func_array(array(object(ProfileController), 'sendProfile'), array(object(Request), 'username' => 'klaughlin')) in Controller.php line 256
at Controller->callAction('sendProfile', array(object(Request), 'username' => 'klaughlin')) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(ProfileController), object(Route), 'sendProfile') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(ProfileController), object(Route), object(Request), 'sendProfile') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ProfileController', 'sendProfile') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Cors.php line 18
at Cors->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Cors), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

这是我的var_dump

object(Symfony\Component\HttpFoundation\File\UploadedFile)#30 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(19) "20160212_124938.jpg" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(10) "image/jpeg" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(1606199) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(14) "/tmp/phpVpVQeP" ["fileName":"SplFileInfo":private]=> string(9) "phpVpVQeP" } string(14) "1483214733.jpg" string(76) "/home/laughlindavid/public_html/mealog.com/public/profilepics/1483214733.jpg" 

对于某些图像来说,这是多么奇怪。

这是我控制器中的代码。

$image = Input::file('picture');
var_dump($image);
$filename  = time() . '.' . $image->getClientOriginalExtension();
var_dump($filename);
$path = public_path('profilepics/' . $filename);
var_dump($path);

Image::make($image->getRealPath())->resize(200, 200)->save($path);

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。我在安装imagick驱动程序并将driver设置为imagick (config/image.php)而不是GD后解决了问题。

答案 1 :(得分:1)

这个错误可能有很多不同的解决方案,但我希望这会帮助那里的人。简短的回答是我的php版本5.6抛出gd.jpeg警告,这可能导致它在我的干预图像Decoder.php文件中执行var_dump时不显示为gd资源。也许使用图像Imagick驱动程序而不是GD驱动程序可以解决这个问题。但是我使用了这个警告,PHP VERSION 1.7现在自动执行。

ini_set ('gd.jpeg_ignore_warning', 1);error_reporting(E_ALL & ~E_NOTICE);

太可怕了!我现在所有的图像都是一致上传的,但我认为还有另外一个与此相关的问题。我的图像中包含EXIF数据,导致其中一些数据自动旋转,这很奇怪。幸运的干预图像有一个方法,这个“orientate()”我在创建我的图像时使用。这是我在控制器中的新代码。

            $image = $picture;

            echo '<br>';
            $filename  = time() . '.' . $image->getClientOriginalExtension();

            $path = public_path('profilepics/' . $filename);


        $imageMoved = $image->move(public_path('profilepics'), $filename);

         ini_set ('gd.jpeg_ignore_warning', 1);
         error_reporting(E_ALL & ~E_NOTICE);

                Image::make($path)->resize(200,200)->orientate()->save($path);

我真的希望这可以节省你花在阅读相同错误的完全不同问题上的主要时间。我的建议是将垃圾从你的错误所来自的文件中转出来并比较(至少在我的情况下)非工作图像的工作图像。和平与快乐的编码!