|
|
|
|
@ -1955,17 +1955,25 @@ class OrdersController extends CommonController
|
|
|
|
|
"errormsg" => "html内容不能为空"
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
// 1. 创建临时文件路径
|
|
|
|
|
$options = [
|
|
|
|
|
'format' => 'png', // 图片格式 (png/jpg等)
|
|
|
|
|
'width' => 400, // 图片宽度
|
|
|
|
|
'height' => 200, // 图片高度
|
|
|
|
|
'quality' => 90 // 图片质量 (仅对jpg有效)
|
|
|
|
|
'format' => 'png',
|
|
|
|
|
'width' => 400,
|
|
|
|
|
'height' => 200
|
|
|
|
|
];
|
|
|
|
|
// 3. 生成图片二进制内容
|
|
|
|
|
$imageContent = SnappyImage::setOptions($options)->generateFromHtml($html);
|
|
|
|
|
|
|
|
|
|
// 4. 转换为Base64编码 (添加数据协议头)
|
|
|
|
|
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']);
|
|
|
|
|
// 确保临时目录存在
|
|
|
|
|
Storage::makeDirectory('temp');
|
|
|
|
|
// 2. 生成图片到临时文件(需要两个参数:html内容和输出路径)
|
|
|
|
|
SnappyImage::setOptions($options)
|
|
|
|
|
->generateFromHtml($html, $tempPath);
|
|
|
|
|
|
|
|
|
|
// 3. 读取临时文件内容并转换为Base64
|
|
|
|
|
$imageContent = file_get_contents($tempPath);
|
|
|
|
|
$base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
|
|
|
|
|
|
|
|
|
|
// 4. 删除临时文件(清理资源)
|
|
|
|
|
unlink($tempPath);
|
|
|
|
|
return response()->json([
|
|
|
|
|
"errorcode" => "200",
|
|
|
|
|
"errormsg" => "success",
|
|
|
|
|
|