seven 5 days ago
parent
commit
3fbce43899
1 changed files with 9 additions and 6 deletions
  1. 9 6
      app/Services/LotteryImageService.php

+ 9 - 6
app/Services/LotteryImageService.php

@@ -10,6 +10,7 @@ class LotteryImageService
      * 生成开奖记录图片
      * @param array $records 开奖记录数组
      * @return string 图片的访问URL
+     * @throws \Exception
      */
     public function generate(array $records): string
     {
@@ -27,16 +28,18 @@ class LotteryImageService
             mkdir(dirname($outputPath), 0755, true);
         }
 
-        // ========= 4. 调用Chromium截图 =========
+        // ========= 4. 调用 wkhtmltoimage =========
+        // --quality 100 提高图片质量,可选
         $cmd = sprintf(
-            'chromium --headless --disable-gpu --screenshot=%s --window-size=1200,2000 file://%s',
-            escapeshellarg($outputPath),
-            escapeshellarg($htmlPath)
+            'wkhtmltoimage --quality 100 %s %s',
+            escapeshellarg($htmlPath),
+            escapeshellarg($outputPath)
         );
+
         exec($cmd, $output, $code);
 
-        if ($code !== 0) {
-            throw new \Exception('图片生成失败,请检查是否安装chromium命令');
+        if ($code !== 0 || !file_exists($outputPath)) {
+            throw new \Exception('图片生成失败,请检查是否已安装 wkhtmltoimage 并可在命令行执行');
         }
 
         // ========= 5. 返回访问URL =========