无法使用Docker容器从给定的二进制数据初始化

时间:2019-06-17 14:41:28

标签: php laravel

无法从给定的二进制数据初始化。

我想使用Vue.js使用laravel保存图像 但是,正如我在标题中所写,将返回错误 “无法从给定的二进制数据初始化。” 在laravel中,我将代码编写如下

$image = $request->get('imgUrl1');
$name = time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
$base=base64_decode($image);
Image::make($base)->save(public_path('img/articles/').$name);



imgUrl1: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfcA...
<string is too large to edit>

无法从给定的二进制数据初始化。

"message": "Unable to init from given binary data.",
    "exception": "Intervention\\Image\\Exception\\NotReadableException",
    "file": "/var/www/laravel/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php",
    "line": 113,

请帮助我

1 个答案:

答案 0 :(得分:0)

问题是您正在尝试使用URL的完整内容,包括data:image标头。您可以尝试使用正则表达式手动从字符串中剥离data:image / png ...或简单地使用file_get_contents($ image),该函数应返回解码后的图像,然后将其传递给make方法

$imageData = file_get_contents($request->get('imgUrl1'));
$image = Image::make($imageData);
$image->save();