|
|
@@ -0,0 +1,382 @@
|
|
|
+"""
|
|
|
+步骤:
|
|
|
+1、整理需要处理的款号图-输出款号图文件夹
|
|
|
+2、整理所有相关的图片作为素材图
|
|
|
+3、按要求进行拼接
|
|
|
+"""
|
|
|
+
|
|
|
+import os
|
|
|
+from PIL import ImageFont
|
|
|
+import sys
|
|
|
+import settings
|
|
|
+
|
|
|
+# from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
|
|
|
+# from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
|
|
|
+is_test_plugins = False
|
|
|
+try:
|
|
|
+ is_test_plugins = settings.is_test_plugins
|
|
|
+except:
|
|
|
+ is_test_plugins = False
|
|
|
+
|
|
|
+if is_test_plugins:
|
|
|
+ from custom_plugins.plugins_mode.detail_generate_base import DetailBase
|
|
|
+ from custom_plugins.plugins_mode.pic_deal import PictureProcessing
|
|
|
+else:
|
|
|
+ from plugins_mode.detail_generate_base import DetailBase
|
|
|
+ from plugins_mode.pic_deal import PictureProcessing
|
|
|
+
|
|
|
+plugins_name = "详情模板"
|
|
|
+company_name_list = ["全部"]
|
|
|
+template_name = "huilima-5"
|
|
|
+
|
|
|
+
|
|
|
+# 乐福鞋 详情页
|
|
|
+
|
|
|
+
|
|
|
+class DetailPicGet(DetailBase):
|
|
|
+ need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
|
|
|
+ root = r"{}\resources\detail_temp\huilima\5".format(os.getcwd())
|
|
|
+
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ goods_no,
|
|
|
+ goods_no_value: dict,
|
|
|
+ out_put_dir,
|
|
|
+ windows=None,
|
|
|
+ test=False,
|
|
|
+ excel_data=None,
|
|
|
+ assigned_page_list=None,
|
|
|
+ output_queue=None,
|
|
|
+ **kwargs
|
|
|
+ ):
|
|
|
+
|
|
|
+ super().__init__(
|
|
|
+ goods_no,
|
|
|
+ goods_no_value,
|
|
|
+ out_put_dir,
|
|
|
+ windows=windows,
|
|
|
+ excel_data=excel_data,
|
|
|
+ assigned_page_list=assigned_page_list,
|
|
|
+ output_queue=output_queue,
|
|
|
+ )
|
|
|
+
|
|
|
+ self.template_name = template_name
|
|
|
+ self.root = r"{}\resources\detail_temp\huilima\5".format(os.getcwd())
|
|
|
+ print("run huilima-1 ")
|
|
|
+ self.base_bg_color = (255, 255, 255)
|
|
|
+ self.deal_pic_func_list = [
|
|
|
+ self.deal_pic_1,
|
|
|
+ self.deal_pic_2,
|
|
|
+ self.deal_pic_3,
|
|
|
+ self.deal_pic_4,
|
|
|
+ self.deal_pic_5,
|
|
|
+ self.deal_pic_6,
|
|
|
+ ]
|
|
|
+ if test:
|
|
|
+ self.run_test()
|
|
|
+ else:
|
|
|
+ self.run_all()
|
|
|
+
|
|
|
+ def run_test(self):
|
|
|
+ detailed_images = []
|
|
|
+ detailed_images.append(self.deal_pic_1())
|
|
|
+ detailed_images.append(self.deal_pic_2())
|
|
|
+ detailed_images.append(self.deal_pic_3())
|
|
|
+ detailed_images.append(self.deal_pic_4())
|
|
|
+ detailed_images.append(self.deal_pic_5())
|
|
|
+ detailed_images.append(self.deal_pic_6())
|
|
|
+ img = self.add_pic(detailed_images)
|
|
|
+ if img:
|
|
|
+ self.create_folder(r"{}/{}".format(self.out_put_dir, template_name))
|
|
|
+ img.save(
|
|
|
+ r"{}/{}/{}.jpg".format(
|
|
|
+ self.out_put_dir, template_name, self.goods_no, format="JPEG"
|
|
|
+ )
|
|
|
+ )
|
|
|
+ img.show()
|
|
|
+
|
|
|
+ #
|
|
|
+ def deal_pic_1(self):
|
|
|
+ detailed_images = []
|
|
|
+ pp_bg_1 = PictureProcessing(r"{}\1.jpg".format(self.root), 1600)
|
|
|
+ font_main = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 160)
|
|
|
+ font_sub = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
|
|
|
+ main_text = self.get_text_value("标题")
|
|
|
+ sub_text = self.get_text_value("副标题")
|
|
|
+ _pp = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_main,
|
|
|
+ text=main_text,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ spacing=20,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ _pp_sub = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_sub,
|
|
|
+ text=sub_text,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_bg_1 = pp_bg_1.paste_img(top_img=_pp, value=(0, 232), base="cs")
|
|
|
+ pp_bg_1 = pp_bg_1.paste_img(top_img=_pp_sub, value=(0, 446), base="cs")
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ pp_jpg_1_list = []
|
|
|
+ pp_png_1_list = []
|
|
|
+ pp_jpg, pp_png = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="俯视",
|
|
|
+ )
|
|
|
+ pp_jpg_1_list.append(pp_jpg)
|
|
|
+ pp_jpg_1_list.append(pp_jpg)
|
|
|
+ pp_png_1_list.append(pp_png)
|
|
|
+ pp_png_1_list.append(pp_png)
|
|
|
+ x, y = 0, 0
|
|
|
+ pp_bg_jpg = PictureProcessing("RGB", (1600, 1600), (255, 255, 255))
|
|
|
+ _resize_value = (
|
|
|
+ pp_bg_1.width if len(pp_jpg_1_list) == 1 else pp_bg_1.width - 300
|
|
|
+ )
|
|
|
+
|
|
|
+ for index, pp_jpg in enumerate(pp_jpg_1_list):
|
|
|
+ pp_jpg = pp_jpg.resize(value=_resize_value + 100 * index)
|
|
|
+ pp_bg_jpg = pp_bg_jpg.to_overlay_pic_advance(top_img=pp_jpg, value=(x, y))
|
|
|
+ x += 180
|
|
|
+ y += 60
|
|
|
+
|
|
|
+ x, y = 0, 0
|
|
|
+ pp_bg_png = PictureProcessing("RGBA", (1600, 1600), (255, 255, 255, 0))
|
|
|
+ for index, pp_png in enumerate(pp_png_1_list):
|
|
|
+ pp_png = pp_png.resize(value=_resize_value + 100 * index)
|
|
|
+ pp_bg_png = pp_bg_png.paste_img(top_img=pp_png, value=(x, y))
|
|
|
+ x += 180
|
|
|
+ y += 60
|
|
|
+
|
|
|
+ min_bbox = pp_bg_png.getbbox()
|
|
|
+ min_bbox = PictureProcessing().expand_bbox(min_bbox)
|
|
|
+ pp_bg_jpg = pp_bg_jpg.crop(bbox=min_bbox)
|
|
|
+ pp_bg_png = pp_bg_png.crop(bbox=min_bbox)
|
|
|
+
|
|
|
+ pp_bg_1 = pp_bg_1.to_overlay_pic_advance(
|
|
|
+ top_img=pp_bg_jpg, top_png_img=pp_bg_png, base="cc"
|
|
|
+ )
|
|
|
+ detailed_images.append(pp_bg_1)
|
|
|
+ # detailed_images.append(pp_bg_2)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ # 展示基础信息
|
|
|
+ def deal_pic_2(self):
|
|
|
+ detailed_images = []
|
|
|
+ pp_bg_2 = PictureProcessing(r"{}\2.jpg".format(self.root))
|
|
|
+ font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 130)
|
|
|
+ font_desc = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 48)
|
|
|
+ text = self.get_text_value("设计理念-标题")
|
|
|
+ text_desc = self.get_text_value("设计理念")
|
|
|
+ _pp = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_1,
|
|
|
+ text=text,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ _pp_desc = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_desc,
|
|
|
+ text=text_desc,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ spacing=30,
|
|
|
+ align="center",
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_bg_2 = pp_bg_2.paste_img(top_img=_pp, value=(0, 212), base="nc")
|
|
|
+ pp_bg_2 = pp_bg_2.paste_img(top_img=_pp_desc, value=(0, 533), base="nc")
|
|
|
+ detailed_images.append(pp_bg_2)
|
|
|
+
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ # 颜色展示
|
|
|
+ def deal_pic_3(self):
|
|
|
+ detailed_images = []
|
|
|
+ pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root))
|
|
|
+ font_color = ImageFont.truetype(
|
|
|
+ r"resources\ttf\puhui\Medium.ttf", 34
|
|
|
+ ) # 颜色名称
|
|
|
+ color_pic_list_1 = []
|
|
|
+ for goods_art_no_dict in self.goods_no_value["货号资料"]:
|
|
|
+ color_name = goods_art_no_dict["颜色名称"]
|
|
|
+ goods_art_no = goods_art_no_dict["货号"]
|
|
|
+ pp_jpg = self.get_overlay_pic_from_dict(
|
|
|
+ goods_art_no=goods_art_no,
|
|
|
+ color_name="侧视",
|
|
|
+ bg_color=self.base_bg_color,
|
|
|
+ )
|
|
|
+ pp_jpg = pp_jpg.resize(value=pp_bg.width / 2)
|
|
|
+
|
|
|
+ pp_jpg = pp_jpg.paste_img_invert(
|
|
|
+ top_img=PictureProcessing(
|
|
|
+ "RGBA", (pp_jpg.width, pp_jpg.height + 70), (255, 255, 255, 0)
|
|
|
+ ),
|
|
|
+ base="nw",
|
|
|
+ )
|
|
|
+ text_image = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_color,
|
|
|
+ text="{}".format(color_name),
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_jpg = pp_jpg.paste_img(top_img=text_image, base="sc", value=(0, 10))
|
|
|
+ color_pic_list_1.append(pp_jpg)
|
|
|
+
|
|
|
+ # 颜色列表进行等分展示
|
|
|
+ all_color_pp = PictureProcessing().horizontal_distribution(
|
|
|
+ color_pic_list_1,
|
|
|
+ bg_width=pp_bg.width - 100,
|
|
|
+ line_spacing=10,
|
|
|
+ number_per_row=2,
|
|
|
+ )
|
|
|
+ pp_bg.paste_img(top_img=all_color_pp, base="cc", value=(0, -100))
|
|
|
+ font_category = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
|
|
|
+ text_xiemian = self.get_text_value("鞋面")
|
|
|
+ text_xiedi = self.get_text_value("鞋底")
|
|
|
+ text_neili = self.get_text_value("内里")
|
|
|
+ text_xiedian = self.get_text_value("鞋垫")
|
|
|
+ pp_text_xiemian = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_category,
|
|
|
+ text=text_xiemian,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_xiedian = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_category,
|
|
|
+ text=text_xiedian,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_xiedi = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_category,
|
|
|
+ text=text_xiedi,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_neili = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_category,
|
|
|
+ text=text_neili,
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_bg = pp_bg.paste_img(top_img=pp_text_xiemian, value=(416, 960), base="nw")
|
|
|
+ pp_bg = pp_bg.paste_img(top_img=pp_text_xiedian, value=(416, 1144), base="nw")
|
|
|
+ pp_bg = pp_bg.paste_img(top_img=pp_text_neili, value=(1157, 960), base="nw")
|
|
|
+ pp_bg = pp_bg.paste_img(top_img=pp_text_xiedi, value=(1157, 1144), base="nw")
|
|
|
+ detailed_images.append(pp_bg)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ # 展示细节图
|
|
|
+ def deal_pic_4(self):
|
|
|
+ detailed_images = []
|
|
|
+ bg_image = PictureProcessing(r"{}\4.jpg".format(self.root))
|
|
|
+ text_fill = (255, 255, 255)
|
|
|
+ font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
|
|
|
+ font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
|
|
|
+ text_title = self.get_text_value("细节标题-1")
|
|
|
+ text_sub_title = self.get_text_value("细节副标题-1")
|
|
|
+ pp_text_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_title,
|
|
|
+ text=text_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_sub_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_sub,
|
|
|
+ text=text_sub_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 258))
|
|
|
+ bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
|
|
|
+
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ _,pp_png = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="俯视",
|
|
|
+ )
|
|
|
+ pp_png = pp_png.resize(value=bg_image.width * 2.5)
|
|
|
+ bg_image.paste_img(top_img=pp_png, base="en", value=(0, 800))
|
|
|
+ detailed_images.append(bg_image)
|
|
|
+
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ # 场景图--产品展示
|
|
|
+ def deal_pic_5(self):
|
|
|
+ detailed_images = []
|
|
|
+ bg_image = PictureProcessing(r"{}\5.jpg".format(self.root))
|
|
|
+ text_fill = (255, 255, 255)
|
|
|
+ font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
|
|
|
+ font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
|
|
|
+ text_title = self.get_text_value("细节标题-2")
|
|
|
+ text_sub_title = self.get_text_value("细节副标题-2")
|
|
|
+ pp_text_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_title,
|
|
|
+ text=text_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_sub_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_sub,
|
|
|
+ text=text_sub_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ bg_image.paste_img(top_img=pp_text_title, base="nw", value=(115, 369))
|
|
|
+ bg_image.paste_img(top_img=pp_text_sub_title, base="nw", value=(115, 686))
|
|
|
+
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ _, pp_png = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="俯视",
|
|
|
+ )
|
|
|
+ pp_png = pp_png.resize(value=bg_image.width * 2)
|
|
|
+ bg_image.paste_img(top_img=pp_png, base="nw", value=(-100, 700))
|
|
|
+ detailed_images.append(bg_image)
|
|
|
+
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+ # 场景图--产品展示
|
|
|
+ def deal_pic_6(self):
|
|
|
+ detailed_images = []
|
|
|
+ bg_image = PictureProcessing(r"{}\6.jpg".format(self.root))
|
|
|
+ text_fill = (255, 255, 255)
|
|
|
+ font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
|
|
|
+ font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
|
|
|
+ text_title = self.get_text_value("细节标题-3")
|
|
|
+ text_sub_title = self.get_text_value("细节副标题-3")
|
|
|
+ pp_text_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_title,
|
|
|
+ text=text_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ pp_text_sub_title = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_sub,
|
|
|
+ text=text_sub_title,
|
|
|
+ fill=text_fill,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 158))
|
|
|
+ bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
|
|
|
+
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ _, pp_png = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="侧视",
|
|
|
+ )
|
|
|
+ pp_png = pp_png.resize(value=bg_image.width * 2.5)
|
|
|
+ bg_image.paste_img(top_img=pp_png, base="en", value=(0, 700))
|
|
|
+ detailed_images.append(bg_image)
|
|
|
+
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ # # 添加注意事项
|
|
|
+ # def deal_pic_6(self):
|
|
|
+ # detailed_images = []
|
|
|
+ # detailed_images.append(PictureProcessing(r"{}\20.jpg".format(self.root)))
|
|
|
+ # detailed_images.append(PictureProcessing(r"{}\21.jpg".format(self.root)))
|
|
|
+ # return PictureProcessing(im=self.add_pic(detailed_images))
|