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. 调用 wkhtmltoimage ========= // --quality 100 提高图片质量,可选 $cmd = sprintf( 'wkhtmltoimage --quality 100 %s %s', escapeshellarg($htmlPath), escapeshellarg($outputPath) ); exec($cmd, $output, $code); if ($code !== 0 || !file_exists($outputPath)) { throw new \Exception('图片生成失败,请检查是否已安装 wkhtmltoimage 并可在命令行执行'); } // ========= 5. 返回访问URL ========= return Storage::url('lottery/' . $fileName); } /** * 生成HTML内容 */ protected function buildHtml($records): string { $rows = ''; foreach ($records as $row) { $rows .= '
| 回合 | 结果 | 组合 | 极值 | 尾数 |
|---|