detail_hongqingting1.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. from PIL import ImageFont
  9. import sys
  10. import settings
  11. # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
  12. # from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  13. is_test_plugins = False
  14. try:
  15. is_test_plugins = settings.is_test_plugins
  16. except:
  17. is_test_plugins = False
  18. if is_test_plugins:
  19. from custom_plugins.plugins_mode.detail_generate_base import DetailBase
  20. from custom_plugins.plugins_mode.pic_deal import PictureProcessing
  21. else:
  22. from plugins_mode.detail_generate_base import DetailBase
  23. from plugins_mode.pic_deal import PictureProcessing
  24. plugins_name = "详情模板"
  25. company_name_list = ["红蜻蜓",]
  26. template_name = "hongqingt-1"
  27. class DetailPicGet(DetailBase):
  28. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  29. root = r"{}\resources\detail_temp\hongqingting\1".format(os.getcwd())
  30. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False, excel_data=None,
  31. assigned_page_list=None):
  32. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows, excel_data=excel_data,
  33. assigned_page_list=assigned_page_list)
  34. self.template_name = template_name
  35. self.root = r"{}\resources\detail_temp\hongqingting\1".format(os.getcwd())
  36. print("run hongqingt-1 ")
  37. self.base_bg_color = (228, 196, 147)
  38. bg_color = (246, 246, 246)
  39. self.image_init(bg_color)
  40. self.deal_pic_func_list = [
  41. self.deal_pic_1,
  42. self.deal_pic_2,
  43. self.deal_pic_3,
  44. self.deal_pic_4,
  45. self.deal_pic_5,
  46. ]
  47. self.run_all()
  48. def deal_pic_1(self):
  49. bg_color = (246, 246, 246)
  50. """ 制作主图 """
  51. goods_art_no_list = list(self.data.keys())
  52. pp_1 = self.data[goods_art_no_list[0]]["pic_is_deal"]["侧视"]
  53. pp_image = pp_1.resize(mode="relative",
  54. base="by_im",
  55. value=0,
  56. base_im=PictureProcessing("RGB", (550, 340), (248, 248, 248)),
  57. percentage=0)
  58. pp_image = PictureProcessing("RGB", (550, 340), bg_color).paste_img(
  59. mode="pixel", top_img=pp_image, base="center"
  60. )
  61. bg_img = PictureProcessing(r"{}\image (1).jpg".format(self.root)).paste_img(
  62. mode="pixel", top_img=pp_image, base="nw", value=(26, 263))
  63. # bg_img.show()
  64. # ---------- 第二张图粘贴
  65. pp_2 = self.data[goods_art_no_list[0]]["pic_is_deal"]["俯视"]
  66. pp_image = pp_2.resize(mode="relative",
  67. base="by_im",
  68. value=0,
  69. base_im=PictureProcessing("RGB", (550, 340), (248, 248, 248)),
  70. percentage=0)
  71. pp_image = PictureProcessing("RGB", (550, 340), bg_color).paste_img(
  72. mode="pixel", top_img=pp_image, base="center"
  73. )
  74. bg_img = bg_img.paste_img(
  75. mode="pixel", top_img=pp_image, base="nw", value=(26, 626))
  76. # -------粘贴文字-------
  77. font = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  78. text_list = [("商品款号", self.goods_no_value["款号"], 700, 297),
  79. ("商品面料", self.goods_no_value["商品面料"], 700, 380),
  80. ("商品内里", self.goods_no_value["商品内里"], 700, 469),
  81. ("商品鞋底", self.goods_no_value["商品鞋底"], 700, 549),
  82. ("后帮高", self.goods_no_value["后帮高"], 700, 667),
  83. ("前掌宽", self.goods_no_value["前掌宽"], 700, 751),
  84. ("鞋跟高", self.goods_no_value["鞋跟高"], 700, 828), ]
  85. for i in text_list:
  86. bg_img = bg_img.add_text(mode="pixel",
  87. value=(i[2], i[3]),
  88. font=font,
  89. text="{}:{}".format(i[0], i[1]),
  90. align="center",
  91. spacing=10,
  92. fill=(17, 16, 16))
  93. return bg_img
  94. def deal_pic_2(self):
  95. # 设计师说展示图
  96. # 设计师说
  97. if "FAB说明" not in self.goods_no_value:
  98. return
  99. text = self.goods_no_value["FAB说明"] # FAB说明
  100. if not text:
  101. return
  102. pp_1 = PictureProcessing(r"{}\image (2).jpg".format(self.root))
  103. text = text.replace(r"\n", "\n")
  104. _ = text.split("\n")
  105. text_img = PictureProcessing("RGB", (1200, len(_) * 100 + 30), (255, 255, 255))
  106. font = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  107. text_img = text_img.add_text(mode="pixel",
  108. value=(600, 50),
  109. font=font,
  110. text=text,
  111. anchor="ma",
  112. align="center",
  113. spacing=50,
  114. fill=(83, 83, 83))
  115. new_image = PictureProcessing("RGB", (1200, pp_1.height + text_img.height), (255, 255, 255))
  116. new_image = new_image.paste_img(mode="pixel", top_img=pp_1, value=(0, 0))
  117. new_image = new_image.paste_img(mode="pixel", top_img=text_img, value=(0, pp_1.height))
  118. return new_image
  119. def deal_pic_3(self):
  120. # 制作角度展示图
  121. bg_color = (246, 246, 246)
  122. detailed_images = []
  123. pp_1 = PictureProcessing(r"{}\image (3).jpg".format(self.root))
  124. detailed_images.append(pp_1)
  125. goods_art_no_list = list(self.data.keys())
  126. for index, goods_art_no in enumerate(goods_art_no_list):
  127. if index == 0:
  128. name_list = ["侧视", "俯视", "后跟", "鞋底"]
  129. else:
  130. name_list = ["侧视", "俯视", ]
  131. for _name in name_list:
  132. # 处理图片,需要粘贴到背景等处理
  133. if _name not in self.data[goods_art_no]["pic_is_deal"]:
  134. continue
  135. _pp = self.data[goods_art_no]["pic_is_deal"][_name]
  136. _pp = _pp.resize(mode="pixel", base="width", value=649 if _name == "后跟" else 1058, )
  137. bg_img = PictureProcessing("RGBA", (1200, int(_pp.height + 50)), bg_color)
  138. bg_img = bg_img.paste_img(mode="pixel", top_img=_pp, base="center")
  139. detailed_images.append(bg_img)
  140. # 添加分割线
  141. detailed_images.append(PictureProcessing("RGB", (1200, 50), (255, 255, 255)))
  142. return PictureProcessing(im=self.add_pic(detailed_images))
  143. def deal_pic_4(self):
  144. # 制作详细图
  145. bg_color = (246, 246, 246)
  146. detailed_images = []
  147. pp_1 = PictureProcessing(r"{}\image (4).jpg".format(self.root))
  148. detailed_images.append(pp_1)
  149. name_list = ["俯视", "内里", "后跟", "鞋底"]
  150. goods_art_no = list(self.data.keys())[0]
  151. view_dict = {"俯视": (0, 0, 1100, 1200),
  152. "内里": (-1, -100, 1100, 1200),
  153. "后跟": (0, -100, 1100, 1200),
  154. "鞋底": (0, -100, 1100, 1200),
  155. }
  156. for _name in name_list:
  157. # 处理图片,需要粘贴到背景等处理
  158. if _name not in self.data[goods_art_no]["pic_is_deal"]:
  159. continue
  160. _pp = self.data[goods_art_no]["pic_is_deal"][_name]
  161. _pp = _pp.resize(mode="pixel", base="width", value=1300 if _name == "后跟" else 2200, )
  162. _pp = _pp.crop_img(mode="pixel", base="sw", value=view_dict[_name], color_fill=bg_color)
  163. _pp = _pp.radius(mode="relative", circular_pos=(1, 0, 0, 1), value=100)
  164. bg_pp = PictureProcessing("RGB", (1200, 1316), (255, 255, 255))
  165. bg_pp.paste_img(mode="pixel", top_img=_pp, base="ec", value=(0, 0))
  166. detailed_images.append(bg_pp)
  167. return PictureProcessing(im=self.add_pic(detailed_images))
  168. def deal_pic_5(self):
  169. # 其他图片添加
  170. pp_1 = PictureProcessing(r"{}\image (5).jpg".format(self.root))
  171. return pp_1