detail_hlm_2.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. from PIL import ImageFont
  9. from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
  10. from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  11. class DetailPicGetHLM2(DetailBase):
  12. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  13. root = r"{}\resources\detail_temp\huilima\1".format(os.getcwd())
  14. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False, excel_data=None,
  15. assigned_page_list=None,**kwargs):
  16. super().__init__(goods_no, goods_no_value, out_put_dir,windows=windows)
  17. self.root = r"{}\resources\detail_temp\huilima\1".format(os.getcwd())
  18. self.run()
  19. def run(self):
  20. detailed_images = self.deal_details()
  21. self.create_folder(self.out_put_dir)
  22. detail_path = "{out_put_dir}/{goods_no}/details".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
  23. self.create_folder(detail_path)
  24. join_path = "{out_put_dir}/{goods_no}/拼接图".format(out_put_dir=self.out_put_dir, goods_no=self.goods_no)
  25. self.create_folder(join_path)
  26. for index, pp in enumerate(detailed_images):
  27. pp.im.save("{}/{}({}).jpg".format(detail_path, self.goods_no, str(index + 11).zfill(2)), format="JPEG")
  28. img = self.add_pic(detailed_images)
  29. # img.show()
  30. img.save("{}/1.jpg".format(join_path), format="JPEG")
  31. # ------------移动其他图片---------------------
  32. self.move_other_pic()
  33. return True
  34. def deal_details(self):
  35. bg_color = (246, 246, 246)
  36. self.image_init(bg_color)
  37. detailed_images = []
  38. detailed_images.append(self.deal_pic_1())
  39. detailed_images.append(self.deal_pic_2())
  40. detailed_images.append(self.deal_pic_3())
  41. detailed_images.append(self.deal_pic_4())
  42. detailed_images.append(self.deal_pic_5())
  43. return [x for x in detailed_images if x]
  44. def deal_pic_1(self):
  45. bg_color = (246, 246, 246)
  46. """ 制作主图 """
  47. detailed_images = []
  48. pp_0 = PictureProcessing(r"{}\image (1).jpg".format(self.root))
  49. detailed_images.append(pp_0)
  50. goods_art_no_list = list(self.data.keys())
  51. pp_1 = self.data[goods_art_no_list[0]]["pic_is_deal"]["俯视"]
  52. pp_image = pp_1.resize(mode="relative",
  53. base="by_im",
  54. base_im=PictureProcessing("RGB", (604, 418), (248, 248, 248)))
  55. pp_image = PictureProcessing("RGB", (604, 418), bg_color).paste_img(
  56. mode="pixel", top_img=pp_image, base="center"
  57. )
  58. bg_img = PictureProcessing("RGB", (1200, 918), (255, 255, 255)).paste_img(
  59. mode="pixel", top_img=pp_image, base="nw", value=(26, 26))
  60. # bg_img.show()
  61. # ---------- 第二张图粘贴
  62. pp_2 = self.data[goods_art_no_list[0]]["pic_is_deal"]["侧视"]
  63. pp_image = pp_2.resize(mode="relative",
  64. base="by_im",
  65. base_im=PictureProcessing("RGB", (604, 418), (248, 248, 248)), )
  66. pp_image = PictureProcessing("RGB", (604, 418), bg_color).paste_img(
  67. mode="pixel", top_img=pp_image, base="center"
  68. )
  69. bg_img = bg_img.paste_img(
  70. mode="pixel", top_img=pp_image, base="nw", value=(26, 26 + 26 + 418))
  71. # -------粘贴文字-------
  72. font = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  73. text_list = [("商品款号", self.goods_no_value["款号"], 700, 297),
  74. ("商品面料", self.goods_no_value["商品面料"], 700, 380),
  75. ("商品内里", self.goods_no_value["商品内里"], 700, 469),
  76. ("商品鞋底", self.goods_no_value["商品鞋底"], 700, 549), ]
  77. for i in text_list:
  78. bg_img = bg_img.add_text(mode="pixel",
  79. value=(i[2], i[3]),
  80. font=font,
  81. text="{}:{}".format(i[0], i[1]),
  82. align="center",
  83. spacing=10,
  84. fill=(17, 16, 16))
  85. detailed_images.append(bg_img)
  86. return PictureProcessing(im=self.add_pic(detailed_images))
  87. def deal_pic_2(self):
  88. # 尺码表
  89. pp_1 = PictureProcessing(r"{}\image (2).jpg".format(self.root))
  90. return pp_1
  91. def deal_pic_3(self):
  92. # 细节图展示
  93. bg_color = (246, 246, 246)
  94. detailed_images = []
  95. goods_art_no_list = list(self.data.keys())
  96. view_dict = {"俯视": {"crop_img_value": (-77, 401, 1086, 752),
  97. "crop_img_base": "sw",
  98. "paste_img_value": (0, 0),
  99. "paste_img_base": "center",
  100. },
  101. "侧视": {"crop_img_value": (0, 0, 1086, 752),
  102. "crop_img_base": "sw",
  103. "paste_img_value": (0, 0),
  104. "paste_img_base": "center",
  105. },
  106. }
  107. for index, goods_art_no in enumerate(goods_art_no_list):
  108. if index == 0:
  109. name_list = ["俯视", "侧视", "鞋底", "内里"]
  110. else:
  111. name_list = ["俯视", "侧视", ]
  112. # 第一个颜色
  113. if "俯视" in name_list:
  114. _pp = self.image_one_pic(goods_art_no, "俯视", bg_color=bg_color)
  115. if _pp is None:
  116. continue
  117. bg_img = PictureProcessing("RGBA", (1200, 848), (255, 255, 255))
  118. _pp = (_pp.resize(value=1900)
  119. .crop_img(mode="pixel", base="sw", value=(-77, 0, 1086, 752), color_fill=bg_color)
  120. .radius(circular_pos=(1, 1, 1, 1), mode="relative", value=100)
  121. .paste_img_invert(mode="pixel", top_img=bg_img, base="center")
  122. )
  123. detailed_images.append(_pp)
  124. if "侧视" in name_list:
  125. _pp = self.image_one_pic(goods_art_no, "侧视", bg_color=bg_color)
  126. if _pp is None:
  127. continue
  128. bg_img = PictureProcessing("RGBA", (1200, 848), (255, 255, 255))
  129. _pp = (_pp.resize(value=1733)
  130. .crop_img(mode="pixel", base="wc", value=(715, 0, 1086, 752), color_fill=bg_color)
  131. .radius(circular_pos=(1, 1, 1, 1), mode="relative", value=100)
  132. .paste_img_invert(mode="pixel", top_img=bg_img, base="center")
  133. )
  134. detailed_images.append(_pp)
  135. if "鞋底" in name_list:
  136. _pp = self.image_one_pic(goods_art_no, "鞋底", bg_color=bg_color)
  137. if _pp is None:
  138. continue
  139. bg_img = PictureProcessing("RGBA", (1200, 848), (255, 255, 255))
  140. _pp = (_pp.resize(value=1733)
  141. .crop_img(mode="pixel", base="wc", value=(715, 0, 1086, 752), color_fill=bg_color)
  142. .radius(circular_pos=(1, 1, 1, 1), mode="relative", value=100)
  143. .paste_img_invert(mode="pixel", top_img=bg_img, base="center")
  144. )
  145. detailed_images.append(_pp)
  146. if "内里" in name_list:
  147. _pp = self.image_one_pic(goods_art_no, "内里", bg_color=bg_color)
  148. if _pp is None:
  149. continue
  150. bg_img = PictureProcessing("RGBA", (1200, 848), (255, 255, 255))
  151. _pp = (_pp.resize(value=1663)
  152. .crop_img(mode="pixel", base="wc", value=(-40, 0, 1086, 752), color_fill=bg_color)
  153. .radius(circular_pos=(1, 1, 1, 1), mode="relative", value=100)
  154. .paste_img_invert(mode="pixel", top_img=bg_img, base="center")
  155. )
  156. detailed_images.append(_pp)
  157. return PictureProcessing(im=self.add_pic(detailed_images))
  158. def deal_pic_4(self):
  159. # 制作角度展示图
  160. bg_color = (246, 246, 246)
  161. detailed_images = []
  162. goods_art_no_list = list(self.data.keys())
  163. for index, goods_art_no in enumerate(goods_art_no_list):
  164. if index == 0:
  165. name_list = ["俯视", "侧视", "后跟", "鞋底"]
  166. else:
  167. name_list = ["俯视", ]
  168. for _name in name_list:
  169. # 处理图片,需要粘贴到背景等处理
  170. if _name not in self.data[goods_art_no]["pic_is_deal"]:
  171. continue
  172. _pp = self.data[goods_art_no]["pic_is_deal"][_name]
  173. _pp = _pp.resize(mode="pixel", base="width", value=600 if _name == "后跟" else 1058, )
  174. bg_pp = PictureProcessing("RGB", (1200, int(_pp.height + 50)), bg_color)
  175. bg_pp = bg_pp.paste_img(mode="pixel", top_img=_pp, base="cc", value=(0, 0))
  176. detailed_images.append(bg_pp)
  177. # 分割线
  178. _p = PictureProcessing("RGB", (1200, 50), (255, 255, 255))
  179. detailed_images.append(_p)
  180. return PictureProcessing(im=self.add_pic(detailed_images))
  181. def deal_pic_5(self):
  182. return PictureProcessing(r"{}\image (3).jpg".format(self.root))