|
|
|
|
@ -1958,6 +1958,7 @@ class OrdersController extends CommonController
|
|
|
|
|
// 1. 创建临时文件路径
|
|
|
|
|
$options = [
|
|
|
|
|
'format' => 'png',
|
|
|
|
|
'enable-local-file-access' => true,
|
|
|
|
|
'disable-external-links' => true,
|
|
|
|
|
];
|
|
|
|
|
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']);
|
|
|
|
|
@ -1966,18 +1967,18 @@ class OrdersController extends CommonController
|
|
|
|
|
// 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",
|
|
|
|
|
// "data" => [
|
|
|
|
|
// "base64_image" => $base64Image
|
|
|
|
|
// ]
|
|
|
|
|
// ]);
|
|
|
|
|
$imageContent = file_get_contents($tempPath);
|
|
|
|
|
$base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
|
|
|
|
|
|
|
|
|
|
// 4. 删除临时文件(清理资源)
|
|
|
|
|
unlink($tempPath);
|
|
|
|
|
return response()->json([
|
|
|
|
|
"errorcode" => "200",
|
|
|
|
|
"errormsg" => "success",
|
|
|
|
|
"data" => [
|
|
|
|
|
"base64_image" => $base64Image
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|