|
|
@@ -0,0 +1,271 @@
|
|
|
+"""
|
|
|
+步骤:
|
|
|
+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 = "clothing-1"
|
|
|
+
|
|
|
+
|
|
|
+class A(object):
|
|
|
+ def __init__(self):
|
|
|
+ print("AAAAAAAAAAAAAAAA")
|
|
|
+
|
|
|
+
|
|
|
+class DetailPicGet(DetailBase):
|
|
|
+ need_view = ["正面", "侧视", "背面", "背侧"]
|
|
|
+ root = r"{}\resources\detail_temp\clothing\1".format(os.getcwd())
|
|
|
+ a = A()
|
|
|
+
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ goods_no,
|
|
|
+ goods_no_value: dict,
|
|
|
+ out_put_dir,
|
|
|
+ windows=None,
|
|
|
+ test=False,
|
|
|
+ excel_data=None,
|
|
|
+ assigned_page_list=None,
|
|
|
+ **kwargs,
|
|
|
+ ):
|
|
|
+
|
|
|
+ super().__init__(
|
|
|
+ goods_no,
|
|
|
+ goods_no_value,
|
|
|
+ out_put_dir,
|
|
|
+ windows=windows,
|
|
|
+ excel_data=excel_data,
|
|
|
+ assigned_page_list=assigned_page_list,
|
|
|
+ )
|
|
|
+
|
|
|
+ self.template_name = template_name
|
|
|
+ self.root = r"{}\resources\detail_temp\clothing\1".format(os.getcwd())
|
|
|
+ print("run huilima-1 ")
|
|
|
+ self.base_bg_color = (228, 196, 147)
|
|
|
+ self.deal_pic_func_list = [
|
|
|
+ self.deal_pic_1,
|
|
|
+ self.deal_pic_2,
|
|
|
+ self.deal_pic_3,
|
|
|
+ self.deal_pic_4,
|
|
|
+ ]
|
|
|
+ bg_color = (246, 246, 246)
|
|
|
+ self.image_init(bg_color)
|
|
|
+ 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())
|
|
|
+ img = self.add_pic(detailed_images)
|
|
|
+ img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
|
|
|
+ if img:
|
|
|
+ img.show()
|
|
|
+
|
|
|
+ def deal_pic_1(self):
|
|
|
+ bg_color = (246, 246, 246)
|
|
|
+ """ 制作主图 """
|
|
|
+ detailed_images = []
|
|
|
+ pp_0 = PictureProcessing(r"{}\1.jpg".format(self.root))
|
|
|
+ detailed_images.append(pp_0)
|
|
|
+ bg_img = self.getSpecialImage(category="场景图", instead_category="正面")
|
|
|
+ detailed_images.append(bg_img)
|
|
|
+ fab_bg = PictureProcessing("RGB", (bg_img.width, 400), (255, 255, 255))
|
|
|
+ font_1 = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 30) # 颜色名称
|
|
|
+ _pp = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_1,
|
|
|
+ align="center",
|
|
|
+ text="精选优质混纺面料,兼顾挺括感与舒适度,提升抗皱性与日常实穿性\n风格简约大方,轻松衔接通勤、休闲、轻社交等多种场合穿搭需求\n车线工整牢固,关键部位加固处理,确保耐穿性与长久穿着品质",
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ margins=(0, 0, -100, -100),
|
|
|
+ spacing=20,
|
|
|
+ )
|
|
|
+ fab_bg = fab_bg.paste_img(top_img=_pp, value=(0, 100), base="nc")
|
|
|
+ mianliao = self.get_text_value("商品面料")
|
|
|
+ liliao = self.get_text_value("商品内里")
|
|
|
+ _pp = PictureProcessing().get_text_image_advanced(
|
|
|
+ font=font_1,
|
|
|
+ align="center",
|
|
|
+ text=f"面料:{mianliao} 里料:{liliao}",
|
|
|
+ fill=(0, 0, 0),
|
|
|
+ return_mode="min_image",
|
|
|
+ margins=(0, 0, -100, -100),
|
|
|
+ spacing=20,
|
|
|
+ )
|
|
|
+ fab_bg = fab_bg.paste_img(top_img=_pp, value=(0, 290), base="nc")
|
|
|
+ detailed_images.append(fab_bg)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ def getSpecialImage(self, category="模特图", instead_category="正面", resize=1200):
|
|
|
+ """获取特殊图片"""
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ if self.get_text_value(category):
|
|
|
+ mote_img = PictureProcessing(self.get_text_value(category))
|
|
|
+ mote_img = mote_img.resize(value=resize)
|
|
|
+ else:
|
|
|
+ pp_jpg, pp_png = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name=instead_category,
|
|
|
+ )
|
|
|
+ mote_img = pp_jpg.resize(value=resize)
|
|
|
+ bg_img = PictureProcessing(
|
|
|
+ "RGB", (mote_img.width, mote_img.height), (255, 255, 255)
|
|
|
+ )
|
|
|
+ bg_img = bg_img.paste_img(top_img=mote_img, base="nc", value=(0, 0))
|
|
|
+ return bg_img
|
|
|
+
|
|
|
+ def deal_pic_2(self):
|
|
|
+ detailed_images = []
|
|
|
+ # 尺码表
|
|
|
+ pp_1 = PictureProcessing(r"{}\4.jpg".format(self.root))
|
|
|
+ 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.getSpecialImage(
|
|
|
+ category="模特图", instead_category="正面", resize=pp_1.width
|
|
|
+ )
|
|
|
+ color_pic_list_1.append(pp_jpg)
|
|
|
+
|
|
|
+ # 颜色列表进行等分展示
|
|
|
+ all_color_pp = PictureProcessing().horizontal_distribution(
|
|
|
+ color_pic_list_1, bg_width=1114, line_spacing=10, number_per_row=2
|
|
|
+ )
|
|
|
+ all_color_pp = all_color_pp.paste_img_invert(
|
|
|
+ top_img=PictureProcessing(
|
|
|
+ "RGB", (pp_1.width, all_color_pp.height + 100), (255, 255, 255)
|
|
|
+ ),
|
|
|
+ base="cc",
|
|
|
+ value=(0, 0),
|
|
|
+ )
|
|
|
+ detailed_images.append(pp_1)
|
|
|
+ detailed_images.append(all_color_pp)
|
|
|
+ pp_6 = PictureProcessing(r"{}\6.jpg".format(self.root))
|
|
|
+ # 粘贴模特图
|
|
|
+ detailed_images.append(pp_6)
|
|
|
+ pp_7 = PictureProcessing(r"{}\7.jpg".format(self.root))
|
|
|
+ # 粘贴模特图
|
|
|
+ detailed_images.append(pp_7)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ def deal_pic_3(self):
|
|
|
+ # 细节图展示
|
|
|
+ bg_color = (246, 246, 246)
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ detailed_images = []
|
|
|
+ color_pic_list_1 = []
|
|
|
+ pp_1 = PictureProcessing(r"{}\8.jpg".format(self.root))
|
|
|
+ # 细节展示
|
|
|
+ detailed_images.append(pp_1)
|
|
|
+ pp_jpg = self.getSpecialImage(
|
|
|
+ category="模特图", instead_category="正面", resize=pp_1.width / 2.1
|
|
|
+ )
|
|
|
+ color_pic_list_1.append(pp_jpg)
|
|
|
+ second_pp_jpg, _ = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="背面",
|
|
|
+ )
|
|
|
+ second_pp_jpg = second_pp_jpg.resize(value=pp_1.width / 2.1)
|
|
|
+ color_pic_list_1.append(second_pp_jpg)
|
|
|
+ detail_2_bg = PictureProcessing(
|
|
|
+ "RGB", (pp_1.width / 2.1, second_pp_jpg.height), (255, 255, 255)
|
|
|
+ )
|
|
|
+ detail_2,_= self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="背面",
|
|
|
+ )
|
|
|
+ detail_2 = detail_2.resize(value=pp_1.width*2)
|
|
|
+ detail_2_bg.paste_img(top_img=detail_2, base="cc", value=(150, 0))
|
|
|
+ color_pic_list_1.append(detail_2_bg)
|
|
|
+ detail_3_bg = PictureProcessing(
|
|
|
+ "RGB", (pp_1.width / 2.1, second_pp_jpg.height), (255, 255, 255)
|
|
|
+ )
|
|
|
+ detail_3, _ = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="正面",
|
|
|
+ )
|
|
|
+ detail_3 = detail_3.resize(value=pp_1.width * 2)
|
|
|
+ detail_3 = detail_3.crop(mode="min")
|
|
|
+ detail_3_bg.paste_img(
|
|
|
+ top_img=detail_3,
|
|
|
+ base="cc",
|
|
|
+ value=(0, detail_3.height/4),
|
|
|
+ )
|
|
|
+ color_pic_list_1.append(detail_3_bg)
|
|
|
+ # 颜色列表进行等分展示
|
|
|
+ all_color_pp = PictureProcessing().horizontal_distribution(
|
|
|
+ color_pic_list_1, bg_width=pp_1.width, line_spacing=10, number_per_row=2
|
|
|
+ )
|
|
|
+ all_color_pp = all_color_pp.paste_img_invert(
|
|
|
+ top_img=PictureProcessing(
|
|
|
+ "RGB", (pp_1.width, all_color_pp.height + 100), (255, 255, 255)
|
|
|
+ ),
|
|
|
+ base="cc",
|
|
|
+ value=(0, 0),
|
|
|
+ )
|
|
|
+ detailed_images.append(all_color_pp)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ def deal_pic_4(self):
|
|
|
+ # 制作角度展示图
|
|
|
+ bg_color = (246, 246, 246)
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ detailed_images = []
|
|
|
+
|
|
|
+ pp_10 = PictureProcessing(r"{}\10.jpg".format(self.root))
|
|
|
+ # 模特展示
|
|
|
+ detailed_images.append(pp_10)
|
|
|
+ model_img = self.getSpecialImage(category="模特图", instead_category="正面", resize=pp_10.width)
|
|
|
+ detailed_images.append(model_img)
|
|
|
+ pp_jpg, _ = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="侧视",
|
|
|
+ )
|
|
|
+ ceshi_img = pp_jpg.resize(value=pp_10.width)
|
|
|
+ detailed_images.append(ceshi_img)
|
|
|
+ pp_jpg, _ = self.image_one_pic(
|
|
|
+ return_orign=True,
|
|
|
+ goods_art_no=goods_art_no_list[0],
|
|
|
+ name="背面",
|
|
|
+ )
|
|
|
+ beimian_img = pp_jpg.resize(value=pp_10.width)
|
|
|
+ detailed_images.append(beimian_img)
|
|
|
+ pp_12 = PictureProcessing(r"{}\12.jpg".format(self.root))
|
|
|
+ # 模特展示
|
|
|
+ detailed_images.append(pp_12)
|
|
|
+ return PictureProcessing(im=self.add_pic(detailed_images))
|