Laravel 5.3 Intervention/image NotReadableException using images from urls

心已入冬 提交于 2019-12-12 23:34:31

问题


How do I deal with the following error so that my script doesn't stop working when the exception occurs:

NotReadableException in AbstractDecoder.php line 302: Image source not readable

I've tried using the following ($file is the url of the image):

// Return false if error
try
{
    $img = Image::make($file);
}
catch(NotReadableException $e)
{
    return false;
}

This doesn't seem to catch the exception and return false. What else can I do?


回答1:


You either need the full namespaced exception in the catch area or add the use statement for that exception at the top of the file




回答2:


Add Intervention\Image\Exception\NotReadableException:

use Intervention\Image\Exception\NotReadableException;

try {
    //
} catch(NotReadableException $e) {
    //
}


来源:https://stackoverflow.com/questions/40019973/laravel-5-3-intervention-image-notreadableexception-using-images-from-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!