detail_clothing1.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. "惠利玛",
  27. ]
  28. template_name = "clothing-1"
  29. class A(object):
  30. def __init__(self):
  31. print("AAAAAAAAAAAAAAAA")
  32. class DetailPicGet(DetailBase):
  33. need_view = ["正面", "侧视", "背面", "背侧"]
  34. root = r"{}\resources\detail_temp\clothing\1".format(os.getcwd())
  35. a = A()
  36. def __init__(
  37. self,
  38. goods_no,
  39. goods_no_value: dict,
  40. out_put_dir,
  41. windows=None,
  42. test=False,
  43. excel_data=None,
  44. assigned_page_list=None,
  45. **kwargs,
  46. ):
  47. super().__init__(
  48. goods_no,
  49. goods_no_value,
  50. out_put_dir,
  51. windows=windows,
  52. excel_data=excel_data,
  53. assigned_page_list=assigned_page_list,
  54. )
  55. self.template_name = template_name
  56. self.root = r"{}\resources\detail_temp\clothing\1".format(os.getcwd())
  57. print("run huilima-1 ")
  58. self.base_bg_color = (228, 196, 147)
  59. self.deal_pic_func_list = [
  60. self.deal_pic_1,
  61. self.deal_pic_2,
  62. self.deal_pic_3,
  63. self.deal_pic_4,
  64. ]
  65. bg_color = (246, 246, 246)
  66. self.image_init(bg_color)
  67. if test:
  68. self.run_test()
  69. else:
  70. self.run_all()
  71. def run_test(self):
  72. detailed_images = []
  73. detailed_images.append(self.deal_pic_1())
  74. detailed_images.append(self.deal_pic_2())
  75. detailed_images.append(self.deal_pic_3())
  76. detailed_images.append(self.deal_pic_4())
  77. img = self.add_pic(detailed_images)
  78. img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  79. if img:
  80. img.show()
  81. def deal_pic_1(self):
  82. bg_color = (246, 246, 246)
  83. """ 制作主图 """
  84. detailed_images = []
  85. pp_0 = PictureProcessing(r"{}\1.jpg".format(self.root))
  86. detailed_images.append(pp_0)
  87. image_path = self.goods_no_value["货号资料"][0].get("场景图",None)
  88. bg_img = self.getSpecialImage(path=image_path, instead_category="正面")
  89. detailed_images.append(bg_img)
  90. fab_bg = PictureProcessing("RGB", (bg_img.width, 400), (255, 255, 255))
  91. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 30) # 颜色名称
  92. _pp = PictureProcessing().get_text_image_advanced(
  93. font=font_1,
  94. align="center",
  95. text="精选优质混纺面料,兼顾挺括感与舒适度,提升抗皱性与日常实穿性\n风格简约大方,轻松衔接通勤、休闲、轻社交等多种场合穿搭需求\n车线工整牢固,关键部位加固处理,确保耐穿性与长久穿着品质",
  96. fill=(0, 0, 0),
  97. return_mode="min_image",
  98. margins=(0, 0, -100, -100),
  99. spacing=20,
  100. )
  101. fab_bg = fab_bg.paste_img(top_img=_pp, value=(0, 100), base="nc")
  102. mianliao = self.get_text_value("商品面料")
  103. liliao = self.get_text_value("商品内里")
  104. _pp = PictureProcessing().get_text_image_advanced(
  105. font=font_1,
  106. align="center",
  107. text=f"面料:{mianliao} 里料:{liliao}",
  108. fill=(0, 0, 0),
  109. return_mode="min_image",
  110. margins=(0, 0, -100, -100),
  111. spacing=20,
  112. )
  113. fab_bg = fab_bg.paste_img(top_img=_pp, value=(0, 290), base="nc")
  114. detailed_images.append(fab_bg)
  115. return PictureProcessing(im=self.add_pic(detailed_images))
  116. def getSpecialImage(self, path=None, instead_category="正面", resize=1200):
  117. """获取特殊图片"""
  118. goods_art_no_list = list(self.data.keys())
  119. if path:
  120. mote_img = PictureProcessing(path)
  121. mote_img = mote_img.resize(value=resize)
  122. else:
  123. pp_jpg, pp_png = self.image_one_pic_no_shandow(
  124. return_orign=True,
  125. goods_art_no=goods_art_no_list[0],
  126. name=instead_category,
  127. )
  128. mote_img = pp_jpg.resize(value=resize)
  129. bg_img = PictureProcessing(
  130. "RGB", (mote_img.width, mote_img.height), (255, 255, 255)
  131. )
  132. bg_img = bg_img.paste_img(top_img=mote_img, base="nc", value=(0, 0))
  133. return bg_img
  134. def deal_pic_2(self):
  135. detailed_images = []
  136. # 尺码表
  137. pp_1 = PictureProcessing(r"{}\4.jpg".format(self.root))
  138. color_pic_list_1 = []
  139. for idx,goods_art_no_dict in enumerate(self.goods_no_value["货号资料"]):
  140. # color_name = goods_art_no_dict["颜色名称"]
  141. # goods_art_no = goods_art_no_dict["货号"]
  142. image_path = goods_art_no_dict.get("模特图",None)
  143. if len(self.goods_no_value["货号资料"]) > 1:
  144. pp_jpg = self.getSpecialImage(
  145. path=image_path, instead_category="正面", resize=pp_1.width/2.2
  146. )
  147. else:
  148. pp_jpg = self.getSpecialImage(
  149. path=image_path, instead_category="正面", resize=pp_1.width
  150. )
  151. color_pic_list_1.append(pp_jpg)
  152. # 颜色列表进行等分展示
  153. all_color_pp = PictureProcessing().horizontal_distribution(
  154. color_pic_list_1, bg_width=1114, line_spacing=10, number_per_row=2
  155. )
  156. all_color_pp = all_color_pp.paste_img_invert(
  157. top_img=PictureProcessing(
  158. "RGB", (pp_1.width, all_color_pp.height + 100), (255, 255, 255)
  159. ),
  160. base="cc",
  161. value=(0, 0),
  162. )
  163. detailed_images.append(pp_1)
  164. detailed_images.append(all_color_pp)
  165. pp_6 = PictureProcessing(r"{}\6.jpg".format(self.root))
  166. # 粘贴模特图
  167. detailed_images.append(pp_6)
  168. pp_7 = PictureProcessing(r"{}\7.jpg".format(self.root))
  169. # 粘贴模特图
  170. detailed_images.append(pp_7)
  171. return PictureProcessing(im=self.add_pic(detailed_images))
  172. def deal_pic_3(self):
  173. # 细节图展示
  174. bg_color = (246, 246, 246)
  175. goods_art_no_list = list(self.data.keys())
  176. detailed_images = []
  177. color_pic_list_1 = []
  178. pp_1 = PictureProcessing(r"{}\8.jpg".format(self.root))
  179. # 细节展示
  180. detailed_images.append(pp_1)
  181. image_path = self.goods_no_value["货号资料"][0].get("模特图",None)
  182. pp_jpg = self.getSpecialImage(
  183. path=image_path, instead_category="正面", resize=pp_1.width / 2.1
  184. )
  185. color_pic_list_1.append(pp_jpg)
  186. second_pp_jpg, _ = self.image_one_pic_no_shandow(
  187. return_orign=True,
  188. goods_art_no=goods_art_no_list[0],
  189. name="背面",
  190. )
  191. second_pp_jpg = second_pp_jpg.resize(value=pp_1.width / 2.1)
  192. color_pic_list_1.append(second_pp_jpg)
  193. detail_2_bg = PictureProcessing(
  194. "RGB", (pp_1.width / 2.1, second_pp_jpg.height), (255, 255, 255)
  195. )
  196. detail_2,_= self.image_one_pic_no_shandow(
  197. return_orign=True,
  198. goods_art_no=goods_art_no_list[0],
  199. name="背面",
  200. )
  201. detail_2 = detail_2.resize(value=pp_1.width*2)
  202. detail_2_bg.paste_img(top_img=detail_2, base="cc", value=(150, 0))
  203. color_pic_list_1.append(detail_2_bg)
  204. detail_3_bg = PictureProcessing(
  205. "RGB", (pp_1.width / 2.1, second_pp_jpg.height), (255, 255, 255)
  206. )
  207. detail_3, _ = self.image_one_pic_no_shandow(
  208. return_orign=True,
  209. goods_art_no=goods_art_no_list[0],
  210. name="正面",
  211. )
  212. detail_3 = detail_3.resize(value=pp_1.width * 2)
  213. detail_3 = detail_3.crop(mode="min")
  214. detail_3_bg.paste_img(
  215. top_img=detail_3,
  216. base="cc",
  217. value=(0, detail_3.height/4),
  218. )
  219. color_pic_list_1.append(detail_3_bg)
  220. # 颜色列表进行等分展示
  221. all_color_pp = PictureProcessing().horizontal_distribution(
  222. color_pic_list_1, bg_width=pp_1.width, line_spacing=10, number_per_row=2
  223. )
  224. all_color_pp = all_color_pp.paste_img_invert(
  225. top_img=PictureProcessing(
  226. "RGB", (pp_1.width, all_color_pp.height + 100), (255, 255, 255)
  227. ),
  228. base="cc",
  229. value=(0, 0),
  230. )
  231. detailed_images.append(all_color_pp)
  232. return PictureProcessing(im=self.add_pic(detailed_images))
  233. def deal_pic_4(self):
  234. # 制作角度展示图
  235. bg_color = (246, 246, 246)
  236. goods_art_no_list = list(self.data.keys())
  237. detailed_images = []
  238. pp_10 = PictureProcessing(r"{}\10.jpg".format(self.root))
  239. # 模特展示
  240. detailed_images.append(pp_10)
  241. image_path = self.goods_no_value["货号资料"][0].get("模特图",None)
  242. model_img = self.getSpecialImage(path=image_path, instead_category="正面", resize=pp_10.width)
  243. detailed_images.append(model_img)
  244. pp_jpg, _ = self.image_one_pic_no_shandow(
  245. return_orign=True,
  246. goods_art_no=goods_art_no_list[0],
  247. name="侧视",
  248. )
  249. ceshi_img = pp_jpg.resize(value=pp_10.width)
  250. detailed_images.append(ceshi_img)
  251. pp_jpg, _ = self.image_one_pic_no_shandow(
  252. return_orign=True,
  253. goods_art_no=goods_art_no_list[0],
  254. name="背面",
  255. )
  256. beimian_img = pp_jpg.resize(value=pp_10.width)
  257. detailed_images.append(beimian_img)
  258. pp_12 = PictureProcessing(r"{}\12.jpg".format(self.root))
  259. # 模特展示
  260. detailed_images.append(pp_12)
  261. return PictureProcessing(im=self.add_pic(detailed_images))