Преглед изворни кода

1.图片分辨率比例新增1:3和3:1尺寸
2.新增图片分辨率选项接口供前端使用

lh пре 5 часа
родитељ
комит
c8e9ec9c05
3 измењених фајлова са 52 додато и 0 уклоњено
  1. 6 0
      app/Consts/BaseConst.php
  2. 45 0
      app/Http/Controllers/Anime/AnimeController.php
  3. 1 0
      routes/api.php

+ 6 - 0
app/Consts/BaseConst.php

@@ -135,6 +135,8 @@ class BaseConst
             '21:9' => ['width' => 3136, 'height' => 1344],
             '2:1' => ['width' => 2048, 'height' => 1024],
             '1:2' => ['width' => 1024, 'height' => 2048],
+            '3:1' => ['width' => 2460, 'height' => 820],
+            '1:3' => ['width' => 820, 'height' => 2460],
         ],
         '3k' => [
             '1:1' => ['width' => 3072, 'height' => 3072],
@@ -147,6 +149,8 @@ class BaseConst
             '21:9' => ['width' => 3440, 'height' => 1440],
             '2:1' => ['width' => 3072, 'height' => 1536],
             '1:2' => ['width' => 1536, 'height' => 3072],
+            '3:1' => ['width' => 2976, 'height' => 992],
+            '1:3' => ['width' => 992, 'height' => 2976],
         ],
         '4k' => [
             // 4k 受 829 万像素上限约束:长边能到 3840 的取 3840,够不到的取该比例下的最大可行值
@@ -161,6 +165,8 @@ class BaseConst
             '21:9' => ['width' => 3840, 'height' => 1648],
             '2:1' => ['width' => 3840, 'height' => 1920],
             '1:2' => ['width' => 1920, 'height' => 3840],
+            '3:1' => ['width' => 3840, 'height' => 1280],
+            '1:3' => ['width' => 1280, 'height' => 3840],
         ],
     ];
 

+ 45 - 0
app/Http/Controllers/Anime/AnimeController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Anime;
 
 use App\Transformer\Anime\AnimeTransformer;
 use App\Facade\Site;
+use App\Consts\BaseConst;
 use App\Consts\ErrorConst;
 use App\Exceptions\ApiException;
 use App\Libs\ApiResponse;
@@ -96,6 +97,50 @@ class AnimeController extends BaseController
         return $this->success($models);
     }
 
+    /**
+     * 图片生成选项(分辨率档位、画面比例,两者分开展示)
+     *
+     * 数据来源 BaseConst::IMAGE_RESOLUTION_SIZE_MAP;
+     * 选项统一 key/value 结构:key 为接口入参值,value 为前端展示文案
+     */
+    public function imageOptions() {
+        $sizeMap = BaseConst::IMAGE_RESOLUTION_SIZE_MAP;
+
+        // 分辨率档位(2k/3k/4k)
+        $resolutionLabels = [
+            '2k' => '2K',
+            '3k' => '3K',
+            '4k' => '4K',
+        ];
+        $resolutions = [];
+        foreach (array_keys($sizeMap) as $resolution) {
+            $resolutions[] = [
+                'key'   => $resolution,
+                'value' => $resolutionLabels[$resolution] ?? strtoupper($resolution),
+            ];
+        }
+
+        // 画面比例:取各分辨率档位比例的并集并去重(保持常量中出现顺序)
+        $ratioKeys = [];
+        foreach ($sizeMap as $sizes) {
+            foreach (array_keys($sizes) as $ratio) {
+                $ratioKeys[$ratio] = true;
+            }
+        }
+        $ratios = [];
+        foreach (array_keys($ratioKeys) as $ratio) {
+            $ratios[] = [
+                'key'   => $ratio,
+                'value' => $ratio,
+            ];
+        }
+
+        return $this->success([
+            'resolution' => $resolutions,
+            'ratio'      => $ratios,
+        ]);
+    }
+
     // 视频模型
     public function videoModel() {
         $query = DB::table('mp_video_models')->where('is_enabled', 1);

+ 1 - 0
routes/api.php

@@ -201,6 +201,7 @@ Route::group(['middleware' => ['bindToken', 'bindExportToken', 'checkLogin']], f
         Route::group(['prefix' => 'anime'], function () {
             Route::get('textModel', [AnimeController::class, 'textModel']);                         // 文字模型
             Route::get('imageModel', [AnimeController::class, 'imageModel']);                       // 图片模型
+            Route::get('imageOptions', [AnimeController::class, 'imageOptions']);                   // 图片生成选项(分辨率/比例)
             Route::get('videoModel', [AnimeController::class, 'videoModel']);                       // 视频模型
             Route::get('seedanceModelOptions', [AnimeController::class, 'seedanceModelOptions']);   // Seedance模型生成参数选项
             Route::get('artStyleList', [AnimeController::class, 'artStyleList']);                   // 艺术风格列表