detail_xiaosushuoxie1.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. from plugins_mode.detail_generate_base import DetailBase
  12. from plugins_mode.pic_deal import PictureProcessing
  13. plugins_name = "详情模板"
  14. company_name_list = ["小苏",]
  15. template_name = "xiaosushuoxie-1"
  16. class DetailPicGet(DetailBase):
  17. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  18. root = r"{}\resources\detail_temp\xiaosushuoxie\1".format(os.getcwd())
  19. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False, excel_data=None,
  20. assigned_page_list=None):
  21. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows, excel_data=excel_data,
  22. assigned_page_list=assigned_page_list)
  23. self.template_name = template_name
  24. self.root = r"{}\resources\detail_temp\xiaosushuoxie\1".format(os.getcwd())
  25. self.deal_pic_func_list = [
  26. self.deal_pic_1,
  27. self.deal_pic_2,
  28. self.deal_pic_3,
  29. self.deal_pic_4,
  30. self.deal_pic_5,
  31. ]
  32. if test:
  33. self.run_test()
  34. else:
  35. self.run_all()
  36. def run_test(self):
  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. img = self.add_pic(detailed_images)
  44. img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  45. def deal_pic_1(self):
  46. bg_color = (239, 237, 238)
  47. """ 制作主图 """
  48. detailed_images = []
  49. # -------粘贴文字-------
  50. font = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  51. text_list = []
  52. for _set in [("【品 牌】", "品牌"),
  53. ("【货 号】", "款号"),
  54. ("【鞋面材质】", "鞋面材质"),
  55. ("【系列风格】", "系列风格"),
  56. ("【内里材质】", "内里材质"),
  57. ("【尺 码】", "尺码"),
  58. ("【鞋底材质】", "鞋底材质"),
  59. ("【品牌编码】", "品牌编码"),
  60. ]:
  61. title, key = _set
  62. text = self.get_text_value(key)
  63. if text:
  64. text_list.append(
  65. (title, text)
  66. )
  67. # 文字排列
  68. pp_bg = PictureProcessing(r"{}\bg-1.jpg".format(self.root))
  69. x = 101
  70. y = 98
  71. for _set in text_list:
  72. pp_bg = pp_bg.add_text(mode="pixel",
  73. value=(x, y),
  74. font=font,
  75. text="{}:{}".format(_set[0], _set[1]),
  76. align="left",
  77. spacing=10,
  78. fill=(17, 16, 16))
  79. x += 588
  80. if x > 700:
  81. x = 101
  82. y += 94
  83. # ----------主图放置
  84. y += 10
  85. goods_art_no_list = list(self.data.keys())
  86. pp_jpg, pp_png = self.image_one_pic(goods_art_no=goods_art_no_list[0], name="俯视", return_orign=True)
  87. pp_jpg = pp_jpg.resize(value=1083)
  88. pp_png = pp_png.resize(value=1083)
  89. pp_bg = pp_bg.to_overlay_pic_advance(mode="pixel", top_img=pp_jpg, base="nc", value=(0, y), top_png_img=pp_png)
  90. y += pp_jpg.height
  91. y += 20
  92. # ----------配图粘贴
  93. if len(goods_art_no_list) > 1:
  94. # 大于一个颜色做颜色图展示
  95. pp_list_1, pp_list_2 = [], []
  96. for goods_art_no in goods_art_no_list:
  97. pp_jpg, pp_png = self.image_one_pic(goods_art_no=goods_art_no, name="侧视", return_orign=True)
  98. pp_jpg = pp_jpg.resize(value=400)
  99. pp_png = pp_png.resize(value=400)
  100. pp_list_1.append(pp_jpg)
  101. pp_list_2.append(pp_png)
  102. _pp_jpg = PictureProcessing()
  103. _pp_png = PictureProcessing()
  104. _pp_jpg = _pp_jpg.horizontal_distribution(pp_list=pp_list_1, bg_width=1200, margins=(0, 0, 0, 0),
  105. line_spacing=0,
  106. number_per_row=3)
  107. _pp_png = _pp_png.horizontal_distribution(pp_list=pp_list_2, bg_width=1200, margins=(0, 0, 0, 0),
  108. line_spacing=0,
  109. number_per_row=3)
  110. pp_bg = pp_bg.to_overlay_pic_advance(mode="pixel", top_img=_pp_jpg, base="nc", value=(0, y),
  111. top_png_img=_pp_png)
  112. y += _pp_jpg.height
  113. y += 30
  114. # ------多余的剪裁
  115. if y < pp_bg.height:
  116. # print("触发剪裁")
  117. pp_bg = pp_bg.crop_img(value=(0, 0, pp_bg.width, y))
  118. return pp_bg
  119. def deal_pic_2(self):
  120. """
  121. 细节解析
  122. """
  123. font_1 = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  124. font_2 = ImageFont.truetype(r'resources\ttf\simhei.ttf', 15)
  125. bg_color = (220, 220, 220)
  126. detailed_images = []
  127. goods_art_no_list = list(self.data.keys())
  128. # ------侧视图-------------
  129. pp_2 = self.image_one_pic(goods_art_no=goods_art_no_list[0], name="侧视", bg_color=bg_color)
  130. pp_2 = pp_2.resize(mode="pixel", base="width", value=1327)
  131. pp_2 = PictureProcessing("RGB", (550, 550), bg_color).paste_img(mode="pixel", top_img=pp_2,
  132. base="wc", value=(-90, 0))
  133. # 文字
  134. pp_2 = pp_2.add_text(mode="pixel",
  135. value=(21, 24),
  136. font=font_1,
  137. text="优质质感鞋面",
  138. align="left",
  139. spacing=10,
  140. fill=(28, 28, 28))
  141. pp_2 = pp_2.add_text(mode="pixel",
  142. value=(21, 76),
  143. font=font_2,
  144. text="颇具层次",
  145. align="left",
  146. spacing=10,
  147. fill=(78, 78, 78))
  148. pp_2 = pp_2.add_text(mode="pixel",
  149. value=(21, 115),
  150. font=font_2,
  151. text="时尚质感出众",
  152. align="left",
  153. spacing=10,
  154. fill=(78, 78, 78))
  155. # ------后跟-------------
  156. pp_3 = self.image_one_pic(goods_art_no=goods_art_no_list[0], name="后跟", bg_color=bg_color)
  157. pp_3 = pp_3.resize(mode="pixel", base="width", value=625)
  158. pp_3 = PictureProcessing("RGB", (550, 550), bg_color).paste_img(mode="pixel", top_img=pp_3,
  159. base="cc", value=(0, 0))
  160. # 文字
  161. pp_3 = pp_3.add_text(mode="pixel",
  162. value=(pp_3.width - 21, pp_3.height - 35 * 3),
  163. font=font_2,
  164. text="颇具层次",
  165. align="right",
  166. spacing=10,
  167. anchor="rs",
  168. fill=(78, 78, 78))
  169. pp_3 = pp_3.add_text(mode="pixel",
  170. value=(pp_3.width - 21, pp_3.height - 35 * 2),
  171. font=font_2,
  172. text="时尚质感出众",
  173. align="right",
  174. anchor="rs",
  175. spacing=10,
  176. fill=(78, 78, 78))
  177. pp_3 = pp_3.add_text(mode="pixel",
  178. value=(pp_3.width - 21, pp_3.height - 35),
  179. font=font_1,
  180. text="设计感十足",
  181. anchor="rs",
  182. align="right",
  183. spacing=10,
  184. fill=(28, 28, 28))
  185. # ---------------鞋底图
  186. pp_4 = self.image_one_pic(goods_art_no=goods_art_no_list[0], name="鞋底", bg_color=bg_color)
  187. pp_4 = pp_4.resize(mode="pixel", base="width", value=1635)
  188. pp_4 = PictureProcessing("RGB", (1134, 625), bg_color).paste_img(mode="pixel", top_img=pp_4,
  189. base="wc", value=(198, 0))
  190. # 文字
  191. pp_4 = pp_4.add_text(mode="pixel",
  192. value=(21, 451),
  193. font=font_1,
  194. text="防滑耐磨鞋底",
  195. align="left",
  196. spacing=10,
  197. fill=(28, 28, 28))
  198. pp_4 = pp_4.add_text(mode="pixel",
  199. value=(21, 510),
  200. font=font_2,
  201. text="优质材质",
  202. align="left",
  203. spacing=10,
  204. fill=(78, 78, 78))
  205. pp_4 = pp_4.add_text(mode="pixel",
  206. value=(21, 549),
  207. font=font_2,
  208. text="防滑网纹设计坚固耐磨",
  209. align="left",
  210. spacing=10,
  211. fill=(78, 78, 78))
  212. new_bg = PictureProcessing("RGB", (1200, 40 + pp_2.height + 40 + pp_4.height + 40), (239, 239, 239))
  213. new_bg = new_bg.paste_img(mode="pixel", top_img=pp_2, base="nw", value=(33, 40))
  214. new_bg = new_bg.paste_img(mode="pixel", top_img=pp_3, base="nw", value=(33 + 550 + 33, 40))
  215. new_bg = new_bg.paste_img(mode="pixel", top_img=pp_4, base="nw", value=(33, 40 + pp_2.height + 40))
  216. detailed_images.append(new_bg)
  217. return PictureProcessing(im=self.add_pic(detailed_images))
  218. def deal_pic_3(self):
  219. # 设计理念
  220. bg = PictureProcessing(r"{}\1 (1).jpg".format(self.root))
  221. font_1 = ImageFont.truetype(r'resources\ttf\simhei.ttf', 40)
  222. # 粘贴文字
  223. text = self.get_text_value("设计理念")
  224. if not text:
  225. text = "告别枯燥沉闷日常还原自然本身色彩\n融合工装、复古、运动元素随性出走感受自在的步伐"
  226. bg = bg.add_text(mode="pixel",
  227. value=(164, 328),
  228. font=font_1,
  229. text=text,
  230. align="left",
  231. spacing=15,
  232. fill=(39, 39, 39))
  233. return bg
  234. def deal_pic_4(self):
  235. """ 各个颜色细节展示 """
  236. bg_color = (255, 255, 255)
  237. detailed_images = []
  238. goods_art_no_list = list(self.data.keys())
  239. font_1 = ImageFont.truetype(r'resources\ttf\simhei.ttf', 30)
  240. for goods_art_no_dict in self.goods_no_value["货号资料"]:
  241. color_name = goods_art_no_dict["颜色名称"]
  242. goods_art_no = goods_art_no_dict["货号"]
  243. # ------俯视图-------------
  244. pp_1 = self.image_one_pic(goods_art_no=goods_art_no, name="俯视", bg_color=bg_color)
  245. pp_1 = pp_1.resize(mode="pixel", base="width", value=956)
  246. pp_1 = PictureProcessing("RGB", (1200, 40 + pp_1.height + 40), bg_color).paste_img(mode="pixel",
  247. top_img=pp_1,
  248. base="cc", value=(0, 0))
  249. # 粘贴文字与logo
  250. pp_1 = pp_1.add_text(mode="pixel",
  251. value=(51, 26),
  252. font=font_1,
  253. text=color_name,
  254. align="left",
  255. spacing=10,
  256. fill=(28, 28, 28))
  257. pp_1 = pp_1.paste_img(mode="pixel", top_img=PictureProcessing(
  258. r"{}\1 (4).jpg".format(self.root)), base="nw", value=(51, 72))
  259. # ------后跟-------------
  260. pp_2 = self.image_one_pic(goods_art_no=goods_art_no, name="后跟", bg_color=bg_color)
  261. pp_2 = pp_2.resize(mode="pixel", base="width", value=345)
  262. pp_2 = PictureProcessing("RGB", (537, 356), bg_color).paste_img(mode="pixel", top_img=pp_2,
  263. base="cc", value=(0, 0))
  264. # ------内里-------------
  265. pp_3 = self.image_one_pic(goods_art_no=goods_art_no, name="内里", bg_color=bg_color)
  266. pp_3 = pp_3.resize(mode="pixel", base="width", value=577)
  267. pp_3 = PictureProcessing("RGB", (537, 356), bg_color).paste_img(mode="pixel", top_img=pp_3,
  268. base="cc", value=(0, 0))
  269. bg_pp = PictureProcessing("RGB", (1200, 20 + pp_1.height + 20 + pp_2.height + 20), bg_color)
  270. # 粘贴俯视图
  271. bg_pp = bg_pp.paste_img(mode="pixel", top_img=pp_1, base="nw", value=(0, 0))
  272. # 粘贴后跟
  273. bg_pp = bg_pp.paste_img(mode="pixel", top_img=pp_2, base="nw", value=(51, 20 + pp_1.height + 20))
  274. # 粘贴内里
  275. bg_pp = bg_pp.paste_img(mode="pixel", top_img=pp_3, base="nw", value=(588, 20 + pp_1.height + 20))
  276. detailed_images.append(bg_pp)
  277. return PictureProcessing(im=self.add_pic(detailed_images))
  278. def deal_pic_5(self):
  279. # 其他图片
  280. detailed_images = []
  281. detailed_images.append(
  282. PictureProcessing(r"{}\1 (2-1).jpg".format(self.root)))
  283. detailed_images.append(
  284. PictureProcessing(r"{}\1 (3).jpg".format(self.root)))
  285. return PictureProcessing(im=self.add_pic(detailed_images))
  286. if __name__ == '__main__':
  287. import json
  288. with open(
  289. r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\auto_capture_V2\auto_photo\qt_test\data3.txt",
  290. "r", encoding="utf-8") as f:
  291. data = json.loads(f.read())
  292. for goods_no, value in data.items():
  293. d = DetailPicGetXiaoSuShuoXie(goods_no, value,
  294. out_put_dir=r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\auto_capture_V2\auto_photo\output\2024-11-19\软件-详情图生成")
  295. raise 1