rambo пре 5 месеци
родитељ
комит
bd823bd185

+ 191 - 77
python/custom_plugins/plugins_mode/detail_generate_base.py

@@ -15,14 +15,23 @@ from PIL import Image
 import shutil
 import shutil
 from service.base import get_images, check_path, get_image_mask
 from service.base import get_images, check_path, get_image_mask
 from natsort import ns, natsorted
 from natsort import ns, natsorted
+
 # import math
 # import math
 from PIL import ImageFont
 from PIL import ImageFont
 import settings
 import settings
 
 
 
 
 class DetailBase(object):
 class DetailBase(object):
-    def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, excel_data=None,
-                 assigned_page_list=None, output_queue=None):
+    def __init__(
+        self,
+        goods_no,
+        goods_no_value: dict,
+        out_put_dir,
+        windows=None,
+        excel_data=None,
+        assigned_page_list=None,
+        output_queue=None,
+    ):
         self.goods_no = goods_no
         self.goods_no = goods_no
         self.output_queue = output_queue
         self.output_queue = output_queue
         self.out_put_dir = out_put_dir
         self.out_put_dir = out_put_dir
@@ -79,7 +88,9 @@ class DetailBase(object):
             return False
             return False
 
 
     def del_detail_folder(self):
     def del_detail_folder(self):
-        out_path = "{out_put_dir}/{goods_no}".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
+        out_path = "{out_put_dir}/{goods_no}".format(
+            out_put_dir=self.out_put_dir, goods_no=self.goods_no
+        )
         if not os.path.exists(out_path):
         if not os.path.exists(out_path):
             return
             return
         try:
         try:
@@ -97,7 +108,9 @@ class DetailBase(object):
             self.del_detail_folder()
             self.del_detail_folder()
         detailed_images = self.deal_details()
         detailed_images = self.deal_details()
         self.create_folder(self.out_put_dir)
         self.create_folder(self.out_put_dir)
-        detail_path = "{out_put_dir}/{goods_no}/details".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
+        detail_path = "{out_put_dir}/{goods_no}/details".format(
+            out_put_dir=self.out_put_dir, goods_no=self.goods_no
+        )
         self.create_folder(detail_path)
         self.create_folder(detail_path)
         self.save_to_png(detailed_images=detailed_images, detail_path=detail_path)
         self.save_to_png(detailed_images=detailed_images, detail_path=detail_path)
         # 生成拼接图
         # 生成拼接图
@@ -105,7 +118,9 @@ class DetailBase(object):
 
 
         # ------------移动其他图片---------------------
         # ------------移动其他图片---------------------
         # 获取主图模板列表
         # 获取主图模板列表
-        main_pic_path_list = DetailBase.get_temp_pic_info(root=self.root)["main_pic_path_list"]
+        main_pic_path_list = DetailBase.get_temp_pic_info(root=self.root)[
+            "main_pic_path_list"
+        ]
         if not main_pic_path_list:
         if not main_pic_path_list:
             self.move_other_pic(move_main_pic=True)
             self.move_other_pic(move_main_pic=True)
         else:
         else:
@@ -124,19 +139,26 @@ class DetailBase(object):
                         continue
                         continue
                     color_name = pic_data["颜色名称"]
                     color_name = pic_data["颜色名称"]
 
 
-                    color_file_path = "{out_put_dir}/{goods_no}/{goods_number}".format(out_put_dir=self.out_put_dir,
-                                                                                       goods_no=self.goods_no,
-                                                                                       goods_number=pic_data["编号"])
+                    color_file_path = "{out_put_dir}/{goods_no}/{goods_number}".format(
+                        out_put_dir=self.out_put_dir,
+                        goods_no=self.goods_no,
+                        goods_number=pic_data["编号"],
+                    )
                     for i in self.goods_no_value["data_all_goods_art_info"]:
                     for i in self.goods_no_value["data_all_goods_art_info"]:
                         if color_name in i["color"]:
                         if color_name in i["color"]:
-                            new_path = "{out_put_dir}/{goods_no}/{goods_number}".format(out_put_dir=self.out_put_dir,
-                                                                                        goods_no=self.goods_no,
-                                                                                        goods_number="NUM{}".format(
-                                                                                            i["number"]))
+                            new_path = "{out_put_dir}/{goods_no}/{goods_number}".format(
+                                out_put_dir=self.out_put_dir,
+                                goods_no=self.goods_no,
+                                goods_number="NUM{}".format(i["number"]),
+                            )
                             if not os.path.exists(new_path):
                             if not os.path.exists(new_path):
                                 # 创建文件夹
                                 # 创建文件夹
                                 os.makedirs(new_path)
                                 os.makedirs(new_path)
-                                self.move_one_pic(color_file_path, new_path, "NUM{}".format(i["number"]))
+                                self.move_one_pic(
+                                    color_file_path,
+                                    new_path,
+                                    "NUM{}".format(i["number"]),
+                                )
         return True
         return True
 
 
     # 移动一张图片到新的文件夹
     # 移动一张图片到新的文件夹
@@ -165,7 +187,9 @@ class DetailBase(object):
 
 
     # 生成拼接的图片
     # 生成拼接的图片
     def generate_spliced_picture(self):
     def generate_spliced_picture(self):
-        detail_path = "{out_put_dir}/{goods_no}/details".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
+        detail_path = "{out_put_dir}/{goods_no}/details".format(
+            out_put_dir=self.out_put_dir, goods_no=self.goods_no
+        )
         if not os.path.exists(detail_path):
         if not os.path.exists(detail_path):
             return
             return
         detailed_images = []
         detailed_images = []
@@ -173,7 +197,9 @@ class DetailBase(object):
             detailed_images.append(PictureProcessing(image_data["file_path"]))
             detailed_images.append(PictureProcessing(image_data["file_path"]))
         # 生成拼接图
         # 生成拼接图
         img = self.add_pic(detailed_images)
         img = self.add_pic(detailed_images)
-        join_path = "{out_put_dir}/{goods_no}/拼接图".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
+        join_path = "{out_put_dir}/{goods_no}/拼接图".format(
+            out_put_dir=self.out_put_dir, goods_no=self.goods_no
+        )
         self.create_folder(join_path)
         self.create_folder(join_path)
         img.save("{}/1.jpg".format(join_path), format="JPEG")
         img.save("{}/1.jpg".format(join_path), format="JPEG")
 
 
@@ -189,7 +215,11 @@ class DetailBase(object):
         for index, pp in enumerate(detailed_images):
         for index, pp in enumerate(detailed_images):
             if isinstance(pp, dict):
             if isinstance(pp, dict):
                 continue
                 continue
-            pp.im.save("{}/{}({}).png".format(detail_path, self.goods_no, str(index + 11).zfill(2)))
+            pp.im.save(
+                "{}/{}({}).png".format(
+                    detail_path, self.goods_no, str(index + 11).zfill(2)
+                )
+            )
 
 
     def check_state_end(self):
     def check_state_end(self):
         if self.windows is not None:
         if self.windows is not None:
@@ -224,9 +254,10 @@ class DetailBase(object):
 
 
     def init(self):
     def init(self):
         for goods_art_no_value in self.goods_no_value["货号资料"]:
         for goods_art_no_value in self.goods_no_value["货号资料"]:
-            self.data[goods_art_no_value["货号"]] = {"pics": goods_art_no_value["pics"],
-                                                   "pic_is_deal": {}
-                                                   }
+            self.data[goods_art_no_value["货号"]] = {
+                "pics": goods_art_no_value["pics"],
+                "pic_is_deal": {},
+            }
 
 
     def get_text_value(self, key, subsection_len=0):
     def get_text_value(self, key, subsection_len=0):
         text = ""
         text = ""
@@ -274,9 +305,10 @@ class DetailBase(object):
         """
         """
         return_data = []
         return_data = []
         for goods_art_no in self.data:
         for goods_art_no in self.data:
-            goods_art_no_dict = {"货号": goods_art_no,
-                                 "素材": [],
-                                 }
+            goods_art_no_dict = {
+                "货号": goods_art_no,
+                "素材": [],
+            }
 
 
             # 图片数据重新排序
             # 图片数据重新排序
             pic_data = []
             pic_data = []
@@ -289,15 +321,27 @@ class DetailBase(object):
             for file_name in pic_data:
             for file_name in pic_data:
                 if "阴影" in file_name:
                 if "阴影" in file_name:
                     _, action_name, _ = file_name.split("_")
                     _, action_name, _ = file_name.split("_")
-                    pic_path = self.data[goods_art_no]["pics"]["{}-阴影".format(action_name)]
-                    pic_cutout_path = self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)]
+                    pic_path = self.data[goods_art_no]["pics"][
+                        "{}-阴影".format(action_name)
+                    ]
+                    pic_cutout_path = self.data[goods_art_no]["pics"][
+                        "{}-抠图".format(action_name)
+                    ]
                     if os.path.exists(pic_path) and os.path.exists(pic_cutout_path):
                     if os.path.exists(pic_path) and os.path.exists(pic_cutout_path):
-                        goods_art_no_dict["素材"].append({"名称": action_name, "抠图": pic_cutout_path, "阴影": pic_path})
+                        goods_art_no_dict["素材"].append(
+                            {
+                                "名称": action_name,
+                                "抠图": pic_cutout_path,
+                                "阴影": pic_path,
+                            }
+                        )
             return_data.append(goods_art_no_dict)
             return_data.append(goods_art_no_dict)
 
 
         return return_data
         return return_data
 
 
-    def get_overlay_pic_from_dict(self, goods_art_no, color_name, bg_color) -> PictureProcessing:
+    def get_overlay_pic_from_dict(
+        self, goods_art_no, color_name, bg_color
+    ) -> PictureProcessing:
         self.check_state_end()
         self.check_state_end()
         # 增加逻辑,获取任意货号下的组合图
         # 增加逻辑,获取任意货号下的组合图
         if "组合" in color_name:
         if "组合" in color_name:
@@ -313,9 +357,14 @@ class DetailBase(object):
                     action_name = pic_name.replace("-阴影", "")
                     action_name = pic_name.replace("-阴影", "")
                     if action_name == color_name:
                     if action_name == color_name:
                         pp1 = PictureProcessing(pic_path)
                         pp1 = PictureProcessing(pic_path)
-                        pp2 = PictureProcessing(self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)])
-                        pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(mode="pixel", base="width",
-                                                                                      value=1600)
+                        pp2 = PictureProcessing(
+                            self.data[goods_art_no]["pics"][
+                                "{}-抠图".format(action_name)
+                            ]
+                        )
+                        pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(
+                            mode="pixel", base="width", value=1600
+                        )
                         self.overlay_pic_dict[key] = pp1
                         self.overlay_pic_dict[key] = pp1
 
 
         if key in self.overlay_pic_dict:
         if key in self.overlay_pic_dict:
@@ -328,9 +377,12 @@ class DetailBase(object):
                 if "阴影" in pic_name:
                 if "阴影" in pic_name:
                     action_name = pic_name.replace("-阴影", "")
                     action_name = pic_name.replace("-阴影", "")
                     pp1 = PictureProcessing(pic_path)
                     pp1 = PictureProcessing(pic_path)
-                    pp2 = PictureProcessing(self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)])
-                    pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(mode="pixel", base="width",
-                                                                                  value=1600)
+                    pp2 = PictureProcessing(
+                        self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)]
+                    )
+                    pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(
+                        mode="pixel", base="width", value=1600
+                    )
                     self.data[goods_art_no]["pic_is_deal"][action_name] = pp1
                     self.data[goods_art_no]["pic_is_deal"][action_name] = pp1
 
 
     # 获取任意货号的场景图,优先取指定货号;
     # 获取任意货号的场景图,优先取指定货号;
@@ -361,17 +413,20 @@ class DetailBase(object):
         # 找任意一个有组合图的货号
         # 找任意一个有组合图的货号
         for goods_art_no_dict in self.goods_no_value["货号资料"]:
         for goods_art_no_dict in self.goods_no_value["货号资料"]:
             _goods_art_no = goods_art_no_dict["货号"]
             _goods_art_no = goods_art_no_dict["货号"]
-            if _goods_art_no !=goods_art_no:
+            if _goods_art_no != goods_art_no:
                 continue
                 continue
             _view_name_list = set([x.split("-")[0] for x in goods_art_no_dict["pics"]])
             _view_name_list = set([x.split("-")[0] for x in goods_art_no_dict["pics"]])
             for _view_name in _view_name_list:
             for _view_name in _view_name_list:
                 if "组合" not in _view_name:
                 if "组合" not in _view_name:
                     continue
                     continue
                 data.append(
                 data.append(
-                    {"goods_art_no": _goods_art_no,
-                     "view_name": _view_name,
-                     "real_view_name": "组合1" if _view_name == "组合" else _view_name
-                     }
+                    {
+                        "goods_art_no": _goods_art_no,
+                        "view_name": _view_name,
+                        "real_view_name": (
+                            "组合1" if _view_name == "组合" else _view_name
+                        ),
+                    }
                 )
                 )
         if len(data) <= view_index:
         if len(data) <= view_index:
             return goods_art_no, "无法匹配"
             return goods_art_no, "无法匹配"
@@ -393,10 +448,13 @@ class DetailBase(object):
                 if name != action_name:
                 if name != action_name:
                     continue
                     continue
                 pp1 = PictureProcessing(pic_path)
                 pp1 = PictureProcessing(pic_path)
-                pp2 = PictureProcessing(self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)])
+                pp2 = PictureProcessing(
+                    self.data[goods_art_no]["pics"]["{}-抠图".format(action_name)]
+                )
                 if not return_orign:
                 if not return_orign:
-                    pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(mode="pixel", base="width",
-                                                                                  value=1600)
+                    pp1 = pp1.get_overlay_pic(top_img=pp2, color=bg_color).resize(
+                        mode="pixel", base="width", value=1600
+                    )
                     return pp1
                     return pp1
                 else:
                 else:
                     return pp1, pp2
                     return pp1, pp2
@@ -423,44 +481,68 @@ class DetailBase(object):
                 goods_art_no = goods_art_no_dict["货号"]
                 goods_art_no = goods_art_no_dict["货号"]
             # print("goods_art_no:", goods_art_no)
             # print("goods_art_no:", goods_art_no)
             # 移动颜色图=====================
             # 移动颜色图=====================
-            goods_art_no_f = "{}/{}/{}".format(self.out_put_dir, self.goods_no, goods_art_no)
+            goods_art_no_f = "{}/{}/{}".format(
+                self.out_put_dir, self.goods_no, goods_art_no
+            )
             self.create_folder(goods_art_no_f)
             self.create_folder(goods_art_no_f)
             # 放入一张主图
             # 放入一张主图
             old_pic_path_1 = goods_art_no_dict["800x800"][0]
             old_pic_path_1 = goods_art_no_dict["800x800"][0]
-            shutil.copy(old_pic_path_1,
-                        "{}/{}{}".format(goods_art_no_f, goods_art_no, os.path.splitext(old_pic_path_1)[1]))
+            shutil.copy(
+                old_pic_path_1,
+                "{}/{}{}".format(
+                    goods_art_no_f, goods_art_no, os.path.splitext(old_pic_path_1)[1]
+                ),
+            )
 
 
             # 把其他主图放入作为款号图=====================
             # 把其他主图放入作为款号图=====================
             if move_main_pic:
             if move_main_pic:
                 for pic_path in goods_art_no_dict["800x800"]:
                 for pic_path in goods_art_no_dict["800x800"]:
                     goods_no_main_pic_number += 1
                     goods_no_main_pic_number += 1
                     e = os.path.splitext(pic_path)[1]
                     e = os.path.splitext(pic_path)[1]
-                    shutil.copy(pic_path,
-                                "{out_put_dir}/{goods_no}/{goods_no}({goods_no_main_pic_number}){e}".format(
-                                    out_put_dir=self.out_put_dir, goods_no=self.goods_no,
-                                    goods_no_main_pic_number=str(goods_no_main_pic_number + 10).zfill(2),
-                                    e=e))
+                    shutil.copy(
+                        pic_path,
+                        "{out_put_dir}/{goods_no}/{goods_no}({goods_no_main_pic_number}){e}".format(
+                            out_put_dir=self.out_put_dir,
+                            goods_no=self.goods_no,
+                            goods_no_main_pic_number=str(
+                                goods_no_main_pic_number + 10
+                            ).zfill(2),
+                            e=e,
+                        ),
+                    )
 
 
     def deal_all_main_pic(self):
     def deal_all_main_pic(self):
         """
         """
         处理主图模板,如存在出图模板则进行对应处理
         处理主图模板,如存在出图模板则进行对应处理
         """
         """
         # 获取主图模板列表
         # 获取主图模板列表
-        all_main_pic_path_list = DetailBase.get_temp_pic_info(root=self.root)["main_pic_path_list"]
+        all_main_pic_path_list = DetailBase.get_temp_pic_info(root=self.root)[
+            "main_pic_path_list"
+        ]
         if not all_main_pic_path_list:
         if not all_main_pic_path_list:
             return
             return
         mask_pic_list = DetailBase.get_temp_pic_info(root=self.root)["mask_pic_list"]
         mask_pic_list = DetailBase.get_temp_pic_info(root=self.root)["mask_pic_list"]
         data = self.get_all_process_pics()
         data = self.get_all_process_pics()
         print("========deal_all_main_pic=========主图相关素材:")
         print("========deal_all_main_pic=========主图相关素材:")
 
 
-        view_list = ["组合", "组合2", "组合3", "组合4", "组合5", "组合6", "俯视", "侧视", "后跟", "鞋底", "内里", ]
+        view_list = [
+            "组合",
+            "组合2",
+            "组合3",
+            "组合4",
+            "组合5",
+            "组合6",
+            "俯视",
+            "侧视",
+            "后跟",
+            "鞋底",
+            "内里",
+        ]
 
 
         for _index, main_pic_path_list in enumerate(all_main_pic_path_list):
         for _index, main_pic_path_list in enumerate(all_main_pic_path_list):
             self.check_state_end()
             self.check_state_end()
             out_path_root = "{out_put_dir}/{goods_no}/main_image_{_index}".format(
             out_path_root = "{out_put_dir}/{goods_no}/main_image_{_index}".format(
-                out_put_dir=self.out_put_dir,
-                goods_no=self.goods_no,
-                _index=_index
+                out_put_dir=self.out_put_dir, goods_no=self.goods_no, _index=_index
             )
             )
             check_path(out_path_root)
             check_path(out_path_root)
             if mask_pic_list[_index]:
             if mask_pic_list[_index]:
@@ -488,7 +570,9 @@ class DetailBase(object):
                     if view_name not in _material_sort_dict:
                     if view_name not in _material_sort_dict:
                         continue
                         continue
                     self.check_state_end()
                     self.check_state_end()
-                    pp_jpg, pp_png = self.image_one_pic(goods_art_no, view_name, bg_color=None, return_orign=True)
+                    pp_jpg, pp_png = self.image_one_pic(
+                        goods_art_no, view_name, bg_color=None, return_orign=True
+                    )
                     if not pp_jpg:
                     if not pp_jpg:
                         continue
                         continue
 
 
@@ -514,8 +598,12 @@ class DetailBase(object):
                         mask_x, mask_y = box_size[0], box_size[1]
                         mask_x, mask_y = box_size[0], box_size[1]
                     else:
                     else:
                         mask_width, mask_height = pp_bg.size
                         mask_width, mask_height = pp_bg.size
-                        mask_width, mask_height = int(mask_width * 12 / 16), int(mask_height * 12 / 16)
-                        mask_x, mask_y = int((pp_bg.size[0] - mask_width) / 2), int((pp_bg.size[1] - mask_height) / 2)
+                        mask_width, mask_height = int(mask_width * 12 / 16), int(
+                            mask_height * 12 / 16
+                        )
+                        mask_x, mask_y = int((pp_bg.size[0] - mask_width) / 2), int(
+                            (pp_bg.size[1] - mask_height) / 2
+                        )
 
 
                     if view_name != "后跟":
                     if view_name != "后跟":
                         pp_jpg = pp_jpg.resize(base_by_box=(mask_width, mask_height))
                         pp_jpg = pp_jpg.resize(base_by_box=(mask_width, mask_height))
@@ -524,13 +612,24 @@ class DetailBase(object):
                         # 计算粘贴的位置 mask的位置+图片在mask中的位置
                         # 计算粘贴的位置 mask的位置+图片在mask中的位置
                         p_x = mask_x + int((mask_width - pp_jpg.width) / 2)
                         p_x = mask_x + int((mask_width - pp_jpg.width) / 2)
                         p_y = mask_y + int((mask_height - pp_jpg.height) / 2)
                         p_y = mask_y + int((mask_height - pp_jpg.height) / 2)
-                        pp_bg = pp_bg.to_overlay_pic_advance(mode="pixel", top_img=pp_jpg, base="nw",
-                                                             value=(p_x, p_y), top_png_img=pp_png)
+                        pp_bg = pp_bg.to_overlay_pic_advance(
+                            mode="pixel",
+                            top_img=pp_jpg,
+                            base="nw",
+                            value=(p_x, p_y),
+                            top_png_img=pp_png,
+                        )
                     else:
                     else:
-                        new_mask_width, new_mask_height = int(mask_width / 1.6), int(mask_height / 1.6)
-
-                        pp_jpg = pp_jpg.resize(base_by_box=(new_mask_width, new_mask_height))
-                        pp_png = pp_png.resize(base_by_box=(new_mask_width, new_mask_height))
+                        new_mask_width, new_mask_height = int(mask_width / 1.6), int(
+                            mask_height / 1.6
+                        )
+
+                        pp_jpg = pp_jpg.resize(
+                            base_by_box=(new_mask_width, new_mask_height)
+                        )
+                        pp_png = pp_png.resize(
+                            base_by_box=(new_mask_width, new_mask_height)
+                        )
                         new_mask_x = int((mask_width - new_mask_width) / 2 + mask_x)
                         new_mask_x = int((mask_width - new_mask_width) / 2 + mask_x)
                         new_mask_y = int((mask_height - new_mask_height) / 2 + mask_y)
                         new_mask_y = int((mask_height - new_mask_height) / 2 + mask_y)
 
 
@@ -538,8 +637,13 @@ class DetailBase(object):
                         p_x = new_mask_x + int((new_mask_width - pp_jpg.width) / 2)
                         p_x = new_mask_x + int((new_mask_width - pp_jpg.width) / 2)
                         p_y = new_mask_y + int((new_mask_height - pp_jpg.height) / 2)
                         p_y = new_mask_y + int((new_mask_height - pp_jpg.height) / 2)
 
 
-                        pp_bg = pp_bg.to_overlay_pic_advance(mode="pixel", top_img=pp_jpg, base="nw", value=(p_x, p_y),
-                                                             top_png_img=pp_png)
+                        pp_bg = pp_bg.to_overlay_pic_advance(
+                            mode="pixel",
+                            top_img=pp_jpg,
+                            base="nw",
+                            value=(p_x, p_y),
+                            top_png_img=pp_png,
+                        )
 
 
                     goods_no_main_pic_number += 1
                     goods_no_main_pic_number += 1
                     out_pic_path = "{out_path_root}/{goods_no}({goods_no_main_pic_number}){pic_mode}".format(
                     out_pic_path = "{out_path_root}/{goods_no}({goods_no_main_pic_number}){pic_mode}".format(
@@ -559,8 +663,12 @@ class DetailBase(object):
                     print("392  out_pic_path", out_pic_path)
                     print("392  out_pic_path", out_pic_path)
                     if settings.OUT_PIC_MODE == ".jpg":
                     if settings.OUT_PIC_MODE == ".jpg":
                         pp_bg.save_as_rgb(out_pic_path)
                         pp_bg.save_as_rgb(out_pic_path)
-                    else:
+                    elif settings.OUT_PIC_MODE == ".png":
                         pp_bg.save_as_png(out_pic_path)
                         pp_bg.save_as_png(out_pic_path)
+                    else:
+                        pp_bg.save_as_other(
+                            out_pic_path, settings.OUT_PIC_MODE.split(".")[-1]
+                        )
 
 
     def add_pic(self, detailed_images):
     def add_pic(self, detailed_images):
         self.check_state_end()
         self.check_state_end()
@@ -618,7 +726,7 @@ class DetailBase(object):
                 spacing=5,
                 spacing=5,
                 fill=text_data["fill"],
                 fill=text_data["fill"],
                 return_mode="min_image",
                 return_mode="min_image",
-                margins=(0, 0, 0, 0)
+                margins=(0, 0, 0, 0),
             )
             )
             text_image_list.append(_pp)
             text_image_list.append(_pp)
             if _pp.width > max_w:
             if _pp.width > max_w:
@@ -645,12 +753,13 @@ class DetailBase(object):
         return bg
         return bg
 
 
     def generate_font_list_to_pic(self):
     def generate_font_list_to_pic(self):
-        font_path_list = [r"resources\ttf\puhui\Bold.ttf",
-                          r"resources\ttf\puhui\Medium.ttf",
-                          r"resources\ttf\puhui\Heavy.ttf",
-                          r"resources\ttf\puhui\Light.ttf",
-                          r"resources\ttf\puhui\Regular.ttf",
-                          ]
+        font_path_list = [
+            r"resources\ttf\puhui\Bold.ttf",
+            r"resources\ttf\puhui\Medium.ttf",
+            r"resources\ttf\puhui\Heavy.ttf",
+            r"resources\ttf\puhui\Light.ttf",
+            r"resources\ttf\puhui\Regular.ttf",
+        ]
         text_v_list = [
         text_v_list = [
             "这是一段话Bold",
             "这是一段话Bold",
             "这是一段话Medium",
             "这是一段话Medium",
@@ -663,13 +772,18 @@ class DetailBase(object):
             text_list = []
             text_list = []
             for size in range(26, 80, 2):
             for size in range(26, 80, 2):
                 font = ImageFont.truetype(font_path, size)
                 font = ImageFont.truetype(font_path, size)
-                text_list.append({"text": "{}-字号{}".format(text, size),
-                                  "font": font,
-                                  "fill": (110, 110, 110),
-                                  })
+                text_list.append(
+                    {
+                        "text": "{}-字号{}".format(text, size),
+                        "font": font,
+                        "fill": (110, 110, 110),
+                    }
+                )
             text_image = self.add_text_list(text_list, spacing=15, base="nw")
             text_image = self.add_text_list(text_list, spacing=15, base="nw")
             text_image = text_image.crop(mode="min")
             text_image = text_image.crop(mode="min")
-            text_image = text_image.paste_img_invert(top_img=PictureProcessing("RGB", text_image.size, (255, 255, 255)))
+            text_image = text_image.paste_img_invert(
+                top_img=PictureProcessing("RGB", text_image.size, (255, 255, 255))
+            )
             detailed_images.append(text_image)
             detailed_images.append(text_image)
         return PictureProcessing(im=self.add_pic(detailed_images))
         return PictureProcessing(im=self.add_pic(detailed_images))
 
 

+ 227 - 88
python/custom_plugins/plugins_mode/pic_deal.py

@@ -1,12 +1,15 @@
 import os.path
 import os.path
 
 
 from PIL import Image, ImageDraw, ImageEnhance, ImageFile
 from PIL import Image, ImageDraw, ImageEnhance, ImageFile
+import pillow_avif
 
 
 # import cv2
 # import cv2
 import numpy as np
 import numpy as np
 from blend_modes import multiply
 from blend_modes import multiply
+
 ImageFile.LOAD_TRUNCATED_IMAGES = True
 ImageFile.LOAD_TRUNCATED_IMAGES = True
 
 
+
 class PictureProcessing(object):
 class PictureProcessing(object):
     def __init__(self, *args, **kwargs):
     def __init__(self, *args, **kwargs):
         self.im: Image
         self.im: Image
@@ -34,7 +37,12 @@ class PictureProcessing(object):
         return self.im.getbbox()
         return self.im.getbbox()
 
 
     def expand_bbox(self, bbox, value=100):
     def expand_bbox(self, bbox, value=100):
-        x1, y1, x2, y2 = bbox[0] - value, bbox[1] - value, bbox[2] + value, bbox[3] + value
+        x1, y1, x2, y2 = (
+            bbox[0] - value,
+            bbox[1] - value,
+            bbox[2] + value,
+            bbox[3] + value,
+        )
         if x1 < 0:
         if x1 < 0:
             x1 = 0
             x1 = 0
         if y1 < 0:
         if y1 < 0:
@@ -59,37 +67,50 @@ class PictureProcessing(object):
         # 正片叠底
         # 正片叠底
         top_img: PictureProcessing
         top_img: PictureProcessing
         image_white = Image.new("RGB", (self.get_size()), color)
         image_white = Image.new("RGB", (self.get_size()), color)
-        backdrop_prepped = np.asfarray(image_white.convert('RGBA'))
-        source_prepped = np.asfarray(self.im.convert('RGBA'))
+        backdrop_prepped = np.asfarray(image_white.convert("RGBA"))
+        source_prepped = np.asfarray(self.im.convert("RGBA"))
         blended_np = multiply(backdrop_prepped, source_prepped, 1)
         blended_np = multiply(backdrop_prepped, source_prepped, 1)
-        img = Image.fromarray(np.uint8(blended_np)).convert('RGB')
+        img = Image.fromarray(np.uint8(blended_np)).convert("RGB")
         img.paste(top_img.im, (0, 0), top_img.im)
         img.paste(top_img.im, (0, 0), top_img.im)
         return PictureProcessing(im=img)
         return PictureProcessing(im=img)
 
 
-    def to_overlay_pic_advance(self, mode="pixel", top_img="", base="nw", value=(0, 0), percentage=(0, 0),
-                               margins=(0, 0, 0, 0), opacity=100, top_png_img=None):
+    def to_overlay_pic_advance(
+        self,
+        mode="pixel",
+        top_img="",
+        base="nw",
+        value=(0, 0),
+        percentage=(0, 0),
+        margins=(0, 0, 0, 0),
+        opacity=100,
+        top_png_img=None,
+    ):
         # opacity 透明度
         # opacity 透明度
         # 正片叠底
         # 正片叠底
         _p = PictureProcessing("RGBA", (self.width, self.height), (255, 255, 255, 255))
         _p = PictureProcessing("RGBA", (self.width, self.height), (255, 255, 255, 255))
-        top_img = _p.paste_img(mode=mode,
-                               top_img=top_img,
-                               base=base,
-                               value=value,
-                               percentage=percentage,
-                               margins=margins)
-
-        backdrop_prepped = np.asfarray(self.im.convert('RGBA'))
-        source_prepped = np.asfarray(top_img.im.convert('RGBA'))
+        top_img = _p.paste_img(
+            mode=mode,
+            top_img=top_img,
+            base=base,
+            value=value,
+            percentage=percentage,
+            margins=margins,
+        )
+
+        backdrop_prepped = np.asfarray(self.im.convert("RGBA"))
+        source_prepped = np.asfarray(top_img.im.convert("RGBA"))
         blended_np = multiply(backdrop_prepped, source_prepped, opacity / 100)
         blended_np = multiply(backdrop_prepped, source_prepped, opacity / 100)
-        im = Image.fromarray(np.uint8(blended_np)).convert('RGB')
+        im = Image.fromarray(np.uint8(blended_np)).convert("RGB")
         pp = PictureProcessing(im=im)
         pp = PictureProcessing(im=im)
         if top_png_img:
         if top_png_img:
-            pp = pp.paste_img(mode=mode,
-                              top_img=top_png_img,
-                              base=base,
-                              value=value,
-                              percentage=percentage,
-                              margins=margins)
+            pp = pp.paste_img(
+                mode=mode,
+                top_img=top_png_img,
+                base=base,
+                value=value,
+                percentage=percentage,
+                margins=margins,
+            )
 
 
         return pp
         return pp
 
 
@@ -130,7 +151,15 @@ class PictureProcessing(object):
     def size(self):
     def size(self):
         return self.im.size
         return self.im.size
 
 
-    def resize(self, mode="pixel", base="width", value=0, base_im=None, percentage=0, base_by_box=None):
+    def resize(
+        self,
+        mode="pixel",
+        base="width",
+        value=0,
+        base_im=None,
+        percentage=0,
+        base_by_box=None,
+    ):
         """
         """
         plugins_mode # relative相对(宽度、高度、其他参考图),或  pixel绝对像素
         plugins_mode # relative相对(宽度、高度、其他参考图),或  pixel绝对像素
         base # pixel,width,height,by_im 基于长边、基于短边  (基于短边时,则缩放到指定尺寸)by_im确保能塞进参考图内
         base # pixel,width,height,by_im 基于长边、基于短边  (基于短边时,则缩放到指定尺寸)by_im确保能塞进参考图内
@@ -157,15 +186,27 @@ class PictureProcessing(object):
         if mode == "relative":
         if mode == "relative":
             if base == "width":
             if base == "width":
                 img = self.__to_resize(
                 img = self.__to_resize(
-                    width=self.width * percentage if not base_im else int(base_im.width * percentage))
+                    width=(
+                        self.width * percentage
+                        if not base_im
+                        else int(base_im.width * percentage)
+                    )
+                )
             if base == "height":
             if base == "height":
                 img = self.__to_resize(
                 img = self.__to_resize(
-                    width=self.height * percentage if not base_im else int(base_im.height * percentage))
+                    width=(
+                        self.height * percentage
+                        if not base_im
+                        else int(base_im.height * percentage)
+                    )
+                )
 
 
             # by_im确保能塞进参考图内
             # by_im确保能塞进参考图内
             if base == "by_im":
             if base == "by_im":
                 percentage = 1 if not percentage else percentage
                 percentage = 1 if not percentage else percentage
-                box_width, box_height = int(base_im.width * percentage), int(base_im.height * percentage)
+                box_width, box_height = int(base_im.width * percentage), int(
+                    base_im.height * percentage
+                )
                 width, height = self.width, self.height
                 width, height = self.width, self.height
                 if box_width / box_height < width / height:
                 if box_width / box_height < width / height:
                     scale = box_width / width
                     scale = box_width / width
@@ -175,7 +216,15 @@ class PictureProcessing(object):
 
 
         return PictureProcessing(im=img)
         return PictureProcessing(im=img)
 
 
-    def paste_img(self, mode="pixel", top_img="", base="nw", value=(0, 0), percentage=(0, 0), margins=(0, 0, 0, 0)):
+    def paste_img(
+        self,
+        mode="pixel",
+        top_img="",
+        base="nw",
+        value=(0, 0),
+        percentage=(0, 0),
+        margins=(0, 0, 0, 0),
+    ):
         top_img: PictureProcessing
         top_img: PictureProcessing
         """
         """
         {
         {
@@ -216,7 +265,8 @@ class PictureProcessing(object):
             if base == "nc" or base == "cn":
             if base == "nc" or base == "cn":
                 # 顶部对齐
                 # 顶部对齐
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
-                    (self.height - top_img.height) / 2)
+                    (self.height - top_img.height) / 2
+                )
                 p_x = deviation_x + value[0] + left
                 p_x = deviation_x + value[0] + left
                 p_y = value[1]
                 p_y = value[1]
 
 
@@ -233,7 +283,8 @@ class PictureProcessing(object):
             # 基于底部,左右居中
             # 基于底部,左右居中
             if base == "cs" or base == "sc":
             if base == "cs" or base == "sc":
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
-                    (self.height - top_img.height) / 2)
+                    (self.height - top_img.height) / 2
+                )
 
 
                 p_y = self.height - (top_img.height + value[1] + down)
                 p_y = self.height - (top_img.height + value[1] + down)
                 p_x = deviation_x + value[0] + left
                 p_x = deviation_x + value[0] + left
@@ -241,7 +292,8 @@ class PictureProcessing(object):
             # 上下左右居中
             # 上下左右居中
             if base == "center" or base == "cc":
             if base == "center" or base == "cc":
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
                 deviation_x, deviation_y = int((self.width - top_img.width) / 2), int(
-                    (self.height - top_img.height) / 2)
+                    (self.height - top_img.height) / 2
+                )
                 p_x = deviation_x + value[0] + left
                 p_x = deviation_x + value[0] + left
                 p_y = deviation_y + value[1] + top
                 p_y = deviation_y + value[1] + top
 
 
@@ -271,18 +323,38 @@ class PictureProcessing(object):
 
 
         return PictureProcessing(im=img)
         return PictureProcessing(im=img)
 
 
-    def paste_img_invert(self, mode="pixel", top_img="", base="nw", value=(0, 0), percentage=(0, 0),
-                         margins=(0, 0, 0, 0)):
+    def paste_img_invert(
+        self,
+        mode="pixel",
+        top_img="",
+        base="nw",
+        value=(0, 0),
+        percentage=(0, 0),
+        margins=(0, 0, 0, 0),
+    ):
         top_img: PictureProcessing
         top_img: PictureProcessing
         bg_img = top_img.im
         bg_img = top_img.im
 
 
         top_img = PictureProcessing(im=self.im)
         top_img = PictureProcessing(im=self.im)
         self.im = bg_img
         self.im = bg_img
-        return self.paste_img(mode=mode, top_img=top_img, base=base, value=value, percentage=percentage,
-                              margins=margins)
+        return self.paste_img(
+            mode=mode,
+            top_img=top_img,
+            base=base,
+            value=value,
+            percentage=percentage,
+            margins=margins,
+        )
 
 
     # 水平分布处理,一行N个
     # 水平分布处理,一行N个
-    def horizontal_distribution(self, pp_list, bg_width=1200, margins=(0, 0, 0, 0), line_spacing=0, number_per_row=3, ):
+    def horizontal_distribution(
+        self,
+        pp_list,
+        bg_width=1200,
+        margins=(0, 0, 0, 0),
+        line_spacing=0,
+        number_per_row=3,
+    ):
         """
         """
         pp_list
         pp_list
         line_spacing:行间距
         line_spacing:行间距
@@ -296,14 +368,22 @@ class PictureProcessing(object):
             total_row = total_row + 1
             total_row = total_row + 1
         # print("total_row", total_row)
         # print("total_row", total_row)
         every_height = pp_list[0].height
         every_height = pp_list[0].height
-        bg_pp = PictureProcessing("RGBA", (
-            bg_width, margins[0] + every_height * total_row + line_spacing * (total_row - 1) + margins[1]),
-                                  (255, 255, 255, 0))
+        bg_pp = PictureProcessing(
+            "RGBA",
+            (
+                bg_width,
+                margins[0]
+                + every_height * total_row
+                + line_spacing * (total_row - 1)
+                + margins[1],
+            ),
+            (255, 255, 255, 0),
+        )
 
 
         row_num = 0
         row_num = 0
         y = margins[0]
         y = margins[0]
         for i in range(0, len(pp_list), number_per_row):  # 切片获取每N个元素
         for i in range(0, len(pp_list), number_per_row):  # 切片获取每N个元素
-            row_list = pp_list[i:i + number_per_row]  # 输出每行的元素
+            row_list = pp_list[i : i + number_per_row]  # 输出每行的元素
             if row_list:
             if row_list:
                 row_num += 1
                 row_num += 1
                 # 计算每个元素间距
                 # 计算每个元素间距
@@ -314,16 +394,28 @@ class PictureProcessing(object):
                 # 粘贴每个元素
                 # 粘贴每个元素
                 for pp in row_list:
                 for pp in row_list:
                     x = x + space
                     x = x + space
-                    bg_pp = bg_pp.paste_img(mode="pixel", top_img=pp, base="", value=(x, y))
+                    bg_pp = bg_pp.paste_img(
+                        mode="pixel", top_img=pp, base="", value=(x, y)
+                    )
                     x = x + pp.width
                     x = x + pp.width
 
 
                 if row_num != total_row:
                 if row_num != total_row:
-                    y += (every_height + line_spacing)
+                    y += every_height + line_spacing
         return bg_pp
         return bg_pp
 
 
-    def get_text_image_advanced(self, value=(0, 0), font="", text="", anchor=None, align="left", spacing=0,
-                                fill=(0, 0, 0),
-                                return_mode="image", margins=(0, 0, 0, 0),max_len_one_line=0):
+    def get_text_image_advanced(
+        self,
+        value=(0, 0),
+        font="",
+        text="",
+        anchor=None,
+        align="left",
+        spacing=0,
+        fill=(0, 0, 0),
+        return_mode="image",
+        margins=(0, 0, 0, 0),
+        max_len_one_line=0,
+    ):
         """
         """
         {
         {
             "command": "add_text",
             "command": "add_text",
@@ -360,27 +452,34 @@ class PictureProcessing(object):
         _, _, text_width, text_height = draw_1.textbbox((0, 0), text, font=font)
         _, _, text_width, text_height = draw_1.textbbox((0, 0), text, font=font)
         value = (int(value[0]), int(value[1]))
         value = (int(value[0]), int(value[1]))
 
 
-        draw_1.multiline_text((value[0], value[1] + margins[0]), text,
-                              fill=fill,
-                              font=font,
-                              anchor=anchor,
-                              spacing=spacing,
-                              align=align,
-                              direction=None,
-                              features=None,
-                              language=None,
-                              stroke_width=0,
-                              stroke_fill=None,
-                              embedded_color=False)
+        draw_1.multiline_text(
+            (value[0], value[1] + margins[0]),
+            text,
+            fill=fill,
+            font=font,
+            anchor=anchor,
+            spacing=spacing,
+            align=align,
+            direction=None,
+            features=None,
+            language=None,
+            stroke_width=0,
+            stroke_fill=None,
+            embedded_color=False,
+        )
 
 
         if return_mode == "image":
         if return_mode == "image":
-            pp = pp.paste_img_invert(mode="pixel", top_img=self, base="nw", value=(0, 0))
+            pp = pp.paste_img_invert(
+                mode="pixel", top_img=self, base="nw", value=(0, 0)
+            )
             pass
             pass
         if return_mode == "min_image_high":
         if return_mode == "min_image_high":
             # pp.show()
             # pp.show()
             bbox = pp.getbbox()
             bbox = pp.getbbox()
             bbox = (0, 0, pp.width, bbox[3] + margins[1])
             bbox = (0, 0, pp.width, bbox[3] + margins[1])
-            pp = pp.paste_img_invert(mode="pixel", top_img=self, base="nw", value=(0, 0))
+            pp = pp.paste_img_invert(
+                mode="pixel", top_img=self, base="nw", value=(0, 0)
+            )
             pp = pp.crop(bbox)
             pp = pp.crop(bbox)
 
 
         if return_mode == "min_image":
         if return_mode == "min_image":
@@ -389,8 +488,21 @@ class PictureProcessing(object):
 
 
         return pp
         return pp
 
 
-    def add_text(self, mode="", base="", value="", percentage="", font="", text="", anchor="", align="", direction="",
-                 max_len_one_line="", spacing="", fill=""):
+    def add_text(
+        self,
+        mode="",
+        base="",
+        value="",
+        percentage="",
+        font="",
+        text="",
+        anchor="",
+        align="",
+        direction="",
+        max_len_one_line="",
+        spacing="",
+        fill="",
+    ):
         """
         """
         {
         {
             "command": "add_text",
             "command": "add_text",
@@ -421,22 +533,31 @@ class PictureProcessing(object):
         if mode == "pixel":
         if mode == "pixel":
             xy = value
             xy = value
 
 
-        draw_1.multiline_text(xy, text,
-                              fill=fill,
-                              font=font,
-                              anchor=anchor,
-                              spacing=spacing,
-                              align=align,
-                              direction=None,
-                              features=None,
-                              language=None,
-                              stroke_width=0,
-                              stroke_fill=None,
-                              embedded_color=False)
+        draw_1.multiline_text(
+            xy,
+            text,
+            fill=fill,
+            font=font,
+            anchor=anchor,
+            spacing=spacing,
+            align=align,
+            direction=None,
+            features=None,
+            language=None,
+            stroke_width=0,
+            stroke_fill=None,
+            embedded_color=False,
+        )
         return pp
         return pp
 
 
-    def crop_img(self, mode="pixel", base="nw", value=(100, 100, 10, 10), color_fill=(255, 255, 255),
-                 margins=(0, 0, 0, 0)):
+    def crop_img(
+        self,
+        mode="pixel",
+        base="nw",
+        value=(100, 100, 10, 10),
+        color_fill=(255, 255, 255),
+        margins=(0, 0, 0, 0),
+    ):
         """
         """
         {
         {
             "command": "crop_img",
             "command": "crop_img",
@@ -474,7 +595,12 @@ class PictureProcessing(object):
 
 
             # 右下角
             # 右下角
             if base == "se" or base == "es":
             if base == "se" or base == "es":
-                box = (pp.width - (value[0] + value[2]), pp.height - (value[1] + value[3]), value[2], value[3])
+                box = (
+                    pp.width - (value[0] + value[2]),
+                    pp.height - (value[1] + value[3]),
+                    value[2],
+                    value[3],
+                )
                 # print(box)
                 # print(box)
 
 
             # 居中
             # 居中
@@ -482,10 +608,7 @@ class PictureProcessing(object):
                 # print("11-value", value)
                 # print("11-value", value)
                 x = int((pp.width + value[0] - value[2]) / 2)
                 x = int((pp.width + value[0] - value[2]) / 2)
                 y = int((pp.height + value[1] - value[3]) / 2)
                 y = int((pp.height + value[1] - value[3]) / 2)
-                box = (x,
-                       y,
-                       value[2],
-                       value[3])
+                box = (x, y, value[2], value[3])
                 # print("11-box", box)
                 # print("11-box", box)
 
 
             box = [box[0], box[1], box[0] + box[2], box[1] + box[3]]
             box = [box[0], box[1], box[0] + box[2], box[1] + box[3]]
@@ -497,10 +620,14 @@ class PictureProcessing(object):
         # print("-----")
         # print("-----")
 
 
         if box[0] < 0:
         if box[0] < 0:
-            out_img.paste(Image.new("RGB", (-1 * box[0], out_img.height), color_fill), (0, 0))
+            out_img.paste(
+                Image.new("RGB", (-1 * box[0], out_img.height), color_fill), (0, 0)
+            )
 
 
         if box[1] < 0:
         if box[1] < 0:
-            out_img.paste(Image.new("RGB", (out_img.width, -1 * box[1]), color_fill), (0, 0))
+            out_img.paste(
+                Image.new("RGB", (out_img.width, -1 * box[1]), color_fill), (0, 0)
+            )
 
 
         if box[2] > pp.width:
         if box[2] > pp.width:
             # print(box[2] - img.width, img.height)
             # print(box[2] - img.width, img.height)
@@ -508,8 +635,10 @@ class PictureProcessing(object):
             out_img.paste(i, (pp.width - box[0], 0))
             out_img.paste(i, (pp.width - box[0], 0))
 
 
         if box[3] > pp.height:
         if box[3] > pp.height:
-            out_img.paste(Image.new("RGB", (out_img.width, box[3] - pp.height), color_fill),
-                          (0, pp.height - box[1]))
+            out_img.paste(
+                Image.new("RGB", (out_img.width, box[3] - pp.height), color_fill),
+                (0, pp.height - box[1]),
+            )
 
 
         return PictureProcessing(im=out_img)
         return PictureProcessing(im=out_img)
 
 
@@ -551,7 +680,7 @@ class PictureProcessing(object):
             radii = int(pp.height / 2)
             radii = int(pp.height / 2)
 
 
         # 画圆(用于分离4个角)
         # 画圆(用于分离4个角)
-        circle = Image.new('L', (radii * 2, radii * 2), 0)  # 创建一个黑色背景的画布
+        circle = Image.new("L", (radii * 2, radii * 2), 0)  # 创建一个黑色背景的画布
         draw = ImageDraw.Draw(circle)
         draw = ImageDraw.Draw(circle)
         draw.ellipse((0, 0, radii * 2, radii * 2), fill=255)  # 画白色圆形
         draw.ellipse((0, 0, radii * 2, radii * 2), fill=255)  # 画白色圆形
 
 
@@ -560,7 +689,7 @@ class PictureProcessing(object):
         w, h = img.size
         w, h = img.size
 
 
         # 画4个角(将整圆分离为4个部分)
         # 画4个角(将整圆分离为4个部分)
-        alpha = Image.new('L', img.size, 255)
+        alpha = Image.new("L", img.size, 255)
         _pos = circular_pos
         _pos = circular_pos
         if not _pos:
         if not _pos:
             _pos = (1, 1, 1, 1)
             _pos = (1, 1, 1, 1)
@@ -568,11 +697,18 @@ class PictureProcessing(object):
             if index == 0 and i == 1:
             if index == 0 and i == 1:
                 alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0))  # 左上角
                 alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0))  # 左上角
             if index == 1 and i == 1:
             if index == 1 and i == 1:
-                alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0))  # 右上角
+                alpha.paste(
+                    circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0)
+                )  # 右上角
             if index == 2 and i == 1:
             if index == 2 and i == 1:
-                alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii))  # 右下角
+                alpha.paste(
+                    circle.crop((radii, radii, radii * 2, radii * 2)),
+                    (w - radii, h - radii),
+                )  # 右下角
             if index == 3 and i == 1:
             if index == 3 and i == 1:
-                alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii))  # 左下角
+                alpha.paste(
+                    circle.crop((0, radii, radii, radii * 2)), (0, h - radii)
+                )  # 左下角
         # alpha.show()
         # alpha.show()
         img.putalpha(alpha)  # 白色区域透明可见,黑色区域不可见
         img.putalpha(alpha)  # 白色区域透明可见,黑色区域不可见
         return PictureProcessing(im=img)
         return PictureProcessing(im=img)
@@ -593,3 +729,6 @@ class PictureProcessing(object):
     def save_as_png(self, path):
     def save_as_png(self, path):
         self.im = self.im.convert("RGBA")
         self.im = self.im.convert("RGBA")
         self.im.save(path)
         self.im.save(path)
+
+    def save_as_other(self, path, format):
+        self.im.save(path, format=format)

+ 13 - 2
python/service/base_deal.py

@@ -302,8 +302,17 @@ class BaseDealImage(object):
             )
             )
             if settings.OUT_PIC_MODE == ".jpg":
             if settings.OUT_PIC_MODE == ".jpg":
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".jpg")
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".jpg")
-            else:
+            elif settings.OUT_PIC_MODE == ".png":
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".png")
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".png")
+            else:
+                out_path = "{}/800x800/{}{}".format(
+                    folder_path, file_name, settings.OUT_PIC_MODE
+                )
+            """
+            pp_bg.save_as_other(
+                            out_pic_path, settings.OUT_PIC_MODE.split(".")[-1]
+                        )
+            """
 
 
             out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(folder_path, file_name,
             out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(folder_path, file_name,
                                                               image_dict["image_view"], ".png")
                                                               image_dict["image_view"], ".png")
@@ -801,8 +810,10 @@ class BaseDealImage(object):
                 generate_pic = GeneratePic()
                 generate_pic = GeneratePic()
                 if settings.OUT_PIC_MODE == ".jpg":
                 if settings.OUT_PIC_MODE == ".jpg":
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".jpg")
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".jpg")
-                else:
+                elif settings.OUT_PIC_MODE == ".png":
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".png")
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".png")
+                else:
+                    out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, settings.OUT_PIC_MODE)
 
 
                 out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(goods_art_no_folder_path, file_name,
                 out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(goods_art_no_folder_path, file_name,
                                                                   _name_list[i_n - 1], ".png")
                                                                   _name_list[i_n - 1], ".png")

+ 6 - 1
python/service/generate_main_image/grenerate_main_image_test.py

@@ -601,9 +601,14 @@ class GeneratePic(object):
                 )
                 )
                 # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
                 # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
                 # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
                 # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
-        else:
+        elif settings.OUT_PIC_MODE == ".png":
             self.saver.save_image(image=image_bg, file_path=out_path, save_mode="png")
             self.saver.save_image(image=image_bg, file_path=out_path, save_mode="png")
             # image_bg.save(out_path)
             # image_bg.save(out_path)
+        else:
+            new_format = settings.OUT_PIC_MODE.split(".")[-1]
+            self.saver.save_image(
+                image=image_bg, file_path=out_path, save_mode=new_format
+            )
 
 
         if output_queue is not None:
         if output_queue is not None:
             output_queue.put(True)
             output_queue.put(True)

+ 17 - 2
python/service/grenerate_main_image_test.py

@@ -1,6 +1,7 @@
 import os
 import os
 import copy
 import copy
 import time
 import time
+
 from .image_deal_base_func import *
 from .image_deal_base_func import *
 from PIL import Image, ImageDraw
 from PIL import Image, ImageDraw
 from blend_modes import multiply
 from blend_modes import multiply
@@ -589,7 +590,7 @@ class GeneratePic(object):
                     )
                     )
                     # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=None, dpi=None, _format="JPEG")
                     # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=None, dpi=None, _format="JPEG")
                     # image_bg.save(out_path, format="JPEG")
                     # image_bg.save(out_path, format="JPEG")
-                else:
+                elif settings.OUT_PIC_MODE == ".png":
                     self.saver.save_image(
                     self.saver.save_image(
                         image=image_bg,
                         image=image_bg,
                         file_path=new_file_path,
                         file_path=new_file_path,
@@ -598,11 +599,25 @@ class GeneratePic(object):
                         dpi=(300, 300),
                         dpi=(300, 300),
                         _format="JPEG",
                         _format="JPEG",
                     )
                     )
+                else:
+                    new_format = settings.OUT_PIC_MODE.split(".")[-1]
+                    self.saver.save_image(
+                        image=image_bg,
+                        file_path=new_file_path,
+                        save_mode=new_format,
+                        quality=100,
+                        dpi=(300, 300),
+                        _format=new_format,
+                    )
                     # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
                     # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
                     # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
                     # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
             else:
             else:
+                new_format = settings.OUT_PIC_MODE.split(".")[-1]
                 self.saver.save_image(
                 self.saver.save_image(
-                    image=image_bg, file_path=new_file_path, save_mode="png"
+                    image=image_bg,
+                    file_path=new_file_path,
+                    save_mode=new_format,
+                    _format=new_format,
                 )
                 )
                 # image_bg.save(out_path)
                 # image_bg.save(out_path)
 
 

+ 10 - 2
python/service/match_and_cutout_mode_control/base_deal_image_v2.py

@@ -290,8 +290,12 @@ class BaseDealImage(object):
 
 
             if settings.OUT_PIC_MODE == ".jpg":
             if settings.OUT_PIC_MODE == ".jpg":
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".jpg")
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".jpg")
-            else:
+            elif settings.OUT_PIC_MODE == ".png":
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".png")
                 out_path = "{}/800x800/{}{}".format(folder_path, file_name, ".png")
+            else:
+                out_path = "{}/800x800/{}{}".format(
+                    folder_path, file_name, settings.OUT_PIC_MODE
+                )
 
 
             out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(folder_path, file_name,
             out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(folder_path, file_name,
                                                               image_dict["image_view"], ".png")
                                                               image_dict["image_view"], ".png")
@@ -819,8 +823,12 @@ class BaseDealImage(object):
                 generate_pic = GeneratePic()
                 generate_pic = GeneratePic()
                 if settings.OUT_PIC_MODE == ".jpg":
                 if settings.OUT_PIC_MODE == ".jpg":
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".jpg")
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".jpg")
-                else:
+                elif settings.OUT_PIC_MODE == ".png":
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".png")
                     out_path = "{}/800x800/{}{}".format(goods_art_no_folder_path, file_name, ".png")
+                else:
+                    out_path = "{}/800x800/{}{}".format(
+                        goods_art_no_folder_path, file_name, settings.OUT_PIC_MODE
+                    )
 
 
                 out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(goods_art_no_folder_path, file_name,
                 out_process_path_1 = "{}/阴影图处理/{}_{}_阴影{}".format(goods_art_no_folder_path, file_name,
                                                                   _name_list[i_n - 1], ".png")
                                                                   _name_list[i_n - 1], ".png")

+ 25 - 10
python/service/multi_threaded_image_saving.py

@@ -4,7 +4,7 @@ from concurrent.futures import ThreadPoolExecutor, Future
 from typing import List, Dict, Any
 from typing import List, Dict, Any
 import time
 import time
 from PIL import Image
 from PIL import Image
-
+import pillow_avif
 
 
 class ImageSaver:
 class ImageSaver:
     instance = None
     instance = None
@@ -34,13 +34,16 @@ class ImageSaver:
         :param filename: 图片保存的文件名。
         :param filename: 图片保存的文件名。
         :return: 返回一个Future对象,用于查询任务状态。
         :return: 返回一个Future对象,用于查询任务状态。
         """
         """
-        future = self.executor.submit(self._save_image_worker, image, file_path, **kwargs)
+        future = self.executor.submit(
+            self._save_image_worker, image, file_path, **kwargs
+        )
         with self.lock:
         with self.lock:
-            self.tasks_dict[file_path] = {"is_completed": False,
-                                          "create_time": time.time(),
-                                          "is_error": False,
-                                          "error_info": "",
-                                          }
+            self.tasks_dict[file_path] = {
+                "is_completed": False,
+                "create_time": time.time(),
+                "is_error": False,
+                "error_info": "",
+            }
         return future
         return future
 
 
     def _save_image_worker(self, image: Image, file_path: str, **kwargs) -> None:
     def _save_image_worker(self, image: Image, file_path: str, **kwargs) -> None:
@@ -61,8 +64,16 @@ class ImageSaver:
                 self.tasks_dict[file_path]["is_error"] = True
                 self.tasks_dict[file_path]["is_error"] = True
                 self.tasks_dict[file_path]["error_info"] = "{}".format(e)
                 self.tasks_dict[file_path]["error_info"] = "{}".format(e)
 
 
-    def save_image_by_thread_run(self, image: Image, out_path, save_mode="png", quality=None, dpi=None, _format="JPEG",
-                                 **kwargs):
+    def save_image_by_thread_run(
+        self,
+        image: Image,
+        out_path,
+        save_mode="png",
+        quality=None,
+        dpi=None,
+        _format="JPEG",
+        **kwargs,
+    ):
         if save_mode == "png":
         if save_mode == "png":
             image.save(out_path)
             image.save(out_path)
         else:
         else:
@@ -92,7 +103,11 @@ class ImageSaver:
         :return: 尚未完成保存的图片文件名列表。
         :return: 尚未完成保存的图片文件名列表。
         """
         """
         with self.lock:
         with self.lock:
-            return [file_path for file_path, _value in self.tasks_dict.items() if not _value["is_completed"]]
+            return [
+                file_path
+                for file_path, _value in self.tasks_dict.items()
+                if not _value["is_completed"]
+            ]
 
 
     def __new__(cls, *args, **kwargs):
     def __new__(cls, *args, **kwargs):
         """如果当前没有实例时,调用父类__new__方法,生成示例,有则返回保存的内存地址。"""
         """如果当前没有实例时,调用父类__new__方法,生成示例,有则返回保存的内存地址。"""

+ 3 - 0
python/settings.py

@@ -1,6 +1,7 @@
 from dotenv import load_dotenv, find_dotenv
 from dotenv import load_dotenv, find_dotenv
 from pathlib import Path  # Python 3.6+ only
 from pathlib import Path  # Python 3.6+ only
 import configparser, json, pytz
 import configparser, json, pytz
+import pillow_avif
 
 
 TIME_ZONE = pytz.timezone("Asia/Shanghai")
 TIME_ZONE = pytz.timezone("Asia/Shanghai")
 from numpy import true_divide
 from numpy import true_divide
@@ -43,6 +44,8 @@ def getSysConfigs(key,item,default=None):
     crud = CRUD(SysConfigs)
     crud = CRUD(SysConfigs)
     one_item = crud.read(session, conditions={"key": key})
     one_item = crud.read(session, conditions={"key": key})
     config = json.loads(one_item.value)
     config = json.loads(one_item.value)
+    if item == "main_image_size":
+        print(item, config.get(item, default))
     return config.get(item, default)
     return config.get(item, default)
 
 
 def get_dict_value(_dict, key, default=None):
 def get_dict_value(_dict, key, default=None):

+ 4 - 10
python/temp.py

@@ -1,11 +1,5 @@
-from databases import CRUD, SqlQuery, PhotoRecord, insert_photo_records, DeviceConfig,DeviceConfigTabs
-from datetime import datetime
+from PIL  import Image
+import pillow_avif
 
 
-session = SqlQuery()
-crud = CRUD(DeviceConfigTabs)
-device_tab = DeviceConfigTabs(
-    mode_type=0,
-    mode_name='test',
-)
-create_obj = crud.create(session, obj_in=device_tab)
-print(create_obj.id)
+image = Image.open("test.jpg")
+image.save("abc.webp",format="webp")