|
|
|
|
@ -1958,22 +1958,18 @@ class OrdersController extends CommonController
|
|
|
|
|
// 1. 创建临时文件路径
|
|
|
|
|
$options = [
|
|
|
|
|
'format' => 'png',
|
|
|
|
|
// 'width' => 400,
|
|
|
|
|
// 'height' => 200
|
|
|
|
|
];
|
|
|
|
|
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']);
|
|
|
|
|
// 确保临时目录存在
|
|
|
|
|
Storage::makeDirectory('temp');
|
|
|
|
|
// 2. 生成图片到临时文件(需要两个参数:html内容和输出路径)
|
|
|
|
|
SnappyImage::setOptions($options)
|
|
|
|
|
->generateFromHtml($html, $tempPath);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
unlink($tempPath);
|
|
|
|
|
return response()->json([
|
|
|
|
|
"errorcode" => "200",
|
|
|
|
|
"errormsg" => "success",
|
|
|
|
|
|