buildHtml($records); // ========= 2. 保存HTML到临时文件 ========= $htmlPath = storage_path('app/lottery_temp.html'); file_put_contents($htmlPath, $html); // ========= 3. 输出图片路径 ========= $fileName = 'lottery_' . time() . '.png'; $outputPath = storage_path('app/public/lottery/' . $fileName); if (!is_dir(dirname($outputPath))) { mkdir(dirname($outputPath), 0755, true); } // ========= 4. 调用Chromium截图 ========= $cmd = sprintf( 'chromium --headless --disable-gpu --screenshot=%s --window-size=1200,2000 file://%s', escapeshellarg($outputPath), escapeshellarg($htmlPath) ); exec($cmd, $output, $code); if ($code !== 0) { throw new \Exception('图片生成失败,请检查是否安装chromium命令'); } // ========= 5. 返回访问URL ========= return Storage::url('lottery/' . $fileName); } /** * 生成HTML内容 */ protected function buildHtml(array $records): string { $rows = ''; foreach ($records as $row) { $rows .= '
| 回合 | 结果 | 组合 | 极值 | 尾数 |
|---|