rambo преди 5 месеца
родител
ревизия
afa621a844
променени са 1 файла, в които са добавени 15 реда и са изтрити 15 реда
  1. 15 15
      python/custom_plugins/plugins/detail_template/xinjunlue/detail_xinjunlue1.py

+ 15 - 15
python/custom_plugins/plugins/detail_template/xinjunlue/detail_xinjunlue1.py

@@ -9,7 +9,7 @@ import os
 from PIL import ImageFont, ImageDraw
 import sys
 import settings
-
+from middleware import UnicornException
 # from PIL import Image, ImageDraw, ImageFont
 
 # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
@@ -72,21 +72,21 @@ class DetailPicGet(DetailBase):
         ]
         img = self.add_pic(self.deal_pic_func_list)
         file_path = self.get_text_value("图片路径")
-        # file_path = file_path.replace("\\", "/")
+        if file_path == None or file_path == "":
+            raise UnicornException("图片路径不能为空")
         parent_folder = os.path.dirname(file_path)
-        if os.path.exists(parent_folder) == False:
-            # 确保目标目录存在
-            os.makedirs(parent_folder, exist_ok=True)
-        print("file_path是否存在",parent_folder, os.path.exists(parent_folder))
-        file_extension = file_path.split(".")[-1]
-        format_mapping = {"jpg": "JPEG", "png": "PNG", "webp": "WEBP", "avif": "AVIF"}
-        file_format = format_mapping[file_extension]
-        img.save(file_path, format=file_format)
-        img.show()
-        # if test:
-        #     self.run_test()
-        # else:
-        #     self.run_all()
+        try:
+            if os.path.exists(parent_folder) == False:
+                # 确保目标目录存在
+                os.makedirs(parent_folder, exist_ok=True)
+            file_extension = file_path.split(".")[-1]
+            format_mapping = {"jpg": "JPEG", "png": "PNG", "webp": "WEBP", "avif": "AVIF"}
+            file_format = format_mapping[file_extension.lower()]
+            img.save(file_path, format=file_format)
+        except KeyError:
+            raise UnicornException(f"不支持的文件格式: {file_extension}")
+        except Exception as e:
+            raise UnicornException(f"保存图片时发生错误: {e},请检查路径")
 
     def run_test(self):
         detailed_images = []