Browse Source

[core-ai] ocr api support ImageType

deason 1 month ago
parent
commit
15202b4b37
1 changed files with 55 additions and 0 deletions
  1. 55 0
      core-ai/src/main/java/com/qmth/boot/core/ai/model/ocr/ImageType.java

+ 55 - 0
core-ai/src/main/java/com/qmth/boot/core/ai/model/ocr/ImageType.java

@@ -0,0 +1,55 @@
+package com.qmth.boot.core.ai.model.ocr;
+
+/**
+ * 图片类型
+ */
+public enum ImageType {
+
+    JPG("data:image/jpeg;base64,"),
+
+    PNG("data:image/png;base64,"),
+
+    WEBP("data:image/webp;base64,");
+
+    private String base64Prefix;
+
+    ImageType(String base64Prefix) {
+        this.base64Prefix = base64Prefix;
+    }
+
+    public String getBase64Prefix() {
+        return base64Prefix;
+    }
+
+    public static ImageType find(String fileName) {
+        String imgSuffix = getFileSuffix(fileName);
+        if (imgSuffix == null) {
+            return null;
+        }
+
+        switch (imgSuffix) {
+            case ".jpg":
+            case ".jpeg":
+                return ImageType.JPG;
+            case ".png":
+                return ImageType.PNG;
+            case ".webp":
+                return ImageType.WEBP;
+        }
+        return null;
+    }
+
+    /**
+     * 获取文件后缀名(包含".")
+     */
+    public static String getFileSuffix(String fileName) {
+        if (fileName != null) {
+            int index = fileName.lastIndexOf(".");
+            if (index > -1) {
+                return fileName.substring(index).toLowerCase();
+            }
+        }
+        return null;
+    }
+
+}