master
cody 1 year ago
parent 3708ae16db
commit 8a7581333e

@ -1958,6 +1958,7 @@ class OrdersController extends CommonController
// 1. 创建临时文件路径 // 1. 创建临时文件路径
$options = [ $options = [
'format' => 'png', 'format' => 'png',
'enable-local-file-access' => true,
'disable-external-links' => true, 'disable-external-links' => true,
]; ];
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']); $tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']);
@ -1966,18 +1967,18 @@ class OrdersController extends CommonController
// 2. 生成图片到临时文件(需要两个参数:html内容和输出路径) // 2. 生成图片到临时文件(需要两个参数:html内容和输出路径)
SnappyImage::setOptions($options)->generateFromHtml($html, $tempPath); SnappyImage::setOptions($options)->generateFromHtml($html, $tempPath);
// 3. 读取临时文件内容并转换为Base64 // 3. 读取临时文件内容并转换为Base64
// $imageContent = file_get_contents($tempPath); $imageContent = file_get_contents($tempPath);
// $base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent); $base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
//
// // 4. 删除临时文件(清理资源) // 4. 删除临时文件(清理资源)
// unlink($tempPath); unlink($tempPath);
// return response()->json([ return response()->json([
// "errorcode" => "200", "errorcode" => "200",
// "errormsg" => "success", "errormsg" => "success",
// "data" => [ "data" => [
// "base64_image" => $base64Image "base64_image" => $base64Image
// ] ]
// ]); ]);
} }
} }

Loading…
Cancel
Save