我想压缩上传的图像,并将图像的base64存储在数据库中。每次我在谷歌上搜索问题时,我总是想到要使用存储在特定路径中的图像。我使用的是intervention/image包
我已经试过这个代码了
$img = Image::make($request->photo)->resize(300, 200);
//get the extension
$type = $request->file('photo')->getClientOriginalExtension();
//convert it into the base64.
$base64 = 'data:image/' . $type . ';base64,' . base64_encode(file_get_contents($img));我想在压缩并转换为base64格式后将照片存储在数据库中。Error that I got
发布于 2019-09-13 19:00:17
您不需要编写任何压缩或转换代码。尝试添加encode('data-url')
我希望它能起作用。
$img = Image::make($request->photo)->resize(300, 200)->encode('data-url');https://stackoverflow.com/questions/57921874
复制相似问题