laravel - 使用干预图像从二进制数据调整图像大小
问题描述
我正在尝试使用 Intervention Image 包从从 mysql 表中检索到的数据调整图像的大小。不调整大小它工作正常。我被困在 Image::make 没有返回数据。这是我的代码:
$data = DB::table('accounts')
->leftjoin('coatypes','accounts.type','=','coatypes.typeid')
->leftjoin('attachments','attachments.vno','=','accounts.code')
->where('accounts.type','=',$request->type)
->where('accounts.branchid','=',$branch_id)
->where('attachments.branchid','=',$branch_id)
->where('attachments.vtype','=','Customer')
->select('accounts.*','coatypes.typename','attachments.docfile')
->latest()->get();
foreach($data as &$d) {
$decoded_image = $d->docfile;
$encoded_image = base64_encode($d->docfile);
$img = Image::make($decoded_image)->resize(100, 100);
info($img);
}
编码和解码的图像都在日志中返回空白数据
[2020-02-07 15:51:01] local.INFO:
[2020-02-07 15:51:01] local.INFO:
[2020-02-07 15:51:01] local.INFO:
解决方案
您的数据库中已经有一个 base64 字符串并且不需要base64_encode
或者系统上有图像的路径,在这种情况下,您需要先获取图像内容(使用file_get_contents
),然后再将其编码为 base64。
顺便说一句:
据我所知,干预图像也接受图像路径。
推荐阅读
- bash - 循环遍历 shell 脚本参数并将引用的参数传递给函数
- .net - 由于 dotnet 版本,VSTS 建立在干净的基础上
- javascript - Angular 4 数据表参数
- git - 使用接收后挂钩删除不相关的文件
- python-3.x - 无法从 Windows 10 pro 的 Anaconda 导入 sklearn 和 statsmodels
- oracle - 分析工作区管理器无法启动
- google-cloud-firestore - 来自不同集合的条件的 Firestore 规则
- wamp - 找不到 CORE WAMP 下载,一直只给我插件
- php - Wordpress 前端发布表单 - 图片未上传
- r - 提取 Survfit 线的点的坐标