detail_xinnuo1.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. import settings
  9. from PIL import ImageFont
  10. # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
  11. # from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  12. is_test_plugins = False
  13. try:
  14. is_test_plugins = settings.is_test_plugins
  15. except:
  16. is_test_plugins = False
  17. if is_test_plugins:
  18. from custom_plugins.plugins_mode.detail_generate_base import DetailBase
  19. from custom_plugins.plugins_mode.pic_deal import PictureProcessing
  20. else:
  21. from plugins_mode.detail_generate_base import DetailBase
  22. from plugins_mode.pic_deal import PictureProcessing
  23. plugins_name = "详情模板"
  24. company_name_list = ["信诺"]
  25. template_name = "xinnuo-1"
  26. class DetailPicGet(DetailBase):
  27. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  28. root = r"{}\resources\detail_temp\xinnuo\1".format(os.getcwd())
  29. def __init__(
  30. self,
  31. goods_no,
  32. goods_no_value: dict,
  33. out_put_dir,
  34. windows=None,
  35. test=False,
  36. excel_data=None,
  37. assigned_page_list=None,
  38. ):
  39. super().__init__(
  40. goods_no,
  41. goods_no_value,
  42. out_put_dir,
  43. windows=windows,
  44. excel_data=excel_data,
  45. assigned_page_list=assigned_page_list,
  46. )
  47. self.template_name = template_name
  48. self.root = r"{}\resources\detail_temp\xinnuo\1".format(os.getcwd())
  49. print("run xinnuo-1 ")
  50. self.base_bg_color = (255, 255, 255)
  51. self.base_bg_color_2 = (244, 242, 243)
  52. self.deal_pic_func_list = [
  53. self.deal_pic_1,
  54. self.deal_pic_2,
  55. self.deal_pic_3,
  56. self.deal_pic_4,
  57. self.deal_pic_5,
  58. self.deal_pic_6,
  59. self.deal_pic_7,
  60. self.deal_pic_8,
  61. self.deal_pic_9,
  62. self.deal_pic_10,
  63. self.deal_pic_11,
  64. self.deal_pic_12,
  65. self.deal_pic_13,
  66. self.deal_pic_14,
  67. self.deal_pic_15,
  68. self.deal_pic_16,
  69. self.deal_pic_17,
  70. self.deal_pic_18,
  71. self.deal_pic_19,
  72. self.deal_pic_20,
  73. ]
  74. if test:
  75. # pp = self.generate_font_list_to_pic()
  76. # pp.im.save(r"C:\Users\gymmc\Desktop\细节图示例/字号.png")
  77. # for k, v in self.goods_no_value.items():
  78. # print(k, v)
  79. self.run_test()
  80. else:
  81. self.run_all()
  82. def run_test(self):
  83. detailed_images = []
  84. detailed_images.append(self.deal_pic_1())
  85. detailed_images.append(self.deal_pic_2())
  86. detailed_images.append(self.deal_pic_3())
  87. detailed_images.append(self.deal_pic_4())
  88. detailed_images.append(self.deal_pic_5())
  89. detailed_images.append(self.deal_pic_6())
  90. detailed_images.append(self.deal_pic_7())
  91. # detailed_images.append(self.deal_pic_8())
  92. # detailed_images.append(self.deal_pic_9())
  93. # detailed_images.append(self.deal_pic_10())
  94. # detailed_images.append(self.deal_pic_11())
  95. # detailed_images.append(self.deal_pic_12())
  96. # detailed_images.append(self.deal_pic_13())
  97. # detailed_images.append(self.deal_pic_14())
  98. # detailed_images.append(self.deal_pic_15())
  99. # detailed_images.append(self.deal_pic_16())
  100. # detailed_images.append(self.deal_pic_17())
  101. # detailed_images.append(self.deal_pic_18())
  102. # detailed_images.append(self.deal_pic_19())
  103. # detailed_images.append(self.deal_pic_20())
  104. img = self.add_pic(detailed_images)
  105. img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  106. # img.show()
  107. # 标题文字展示
  108. def deal_pic_1(self):
  109. pp_bg = PictureProcessing(r"{}\1.jpg".format(self.root))
  110. font_main = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 102) # 设计理念
  111. mainTitle = self.get_text_value("主标题")
  112. subTitle = self.get_text_value("副标题")
  113. pp_bg.get_text_image_advanced(
  114. value=(336, 102),
  115. font=font_main,
  116. text=mainTitle,
  117. align="left",
  118. # anchor="ma",
  119. spacing=5,
  120. fill=(60, 40, 29),
  121. return_mode="image",
  122. margins=(0, 0, 0, 0),
  123. )
  124. font_sub = ImageFont.truetype(
  125. r"resources\ttf\puhui\Bold.ttf", 40
  126. ) # 设计理念
  127. pp_bg.get_text_image_advanced(
  128. value=(82, 102),
  129. font=font_sub,
  130. text=subTitle,
  131. align="left",
  132. # anchor="ma",
  133. spacing=5,
  134. fill=(60, 40, 29),
  135. return_mode="image",
  136. margins=(0, 0, 0, 0),
  137. )
  138. return pp_bg
  139. # 展示鞋头和后跟
  140. def deal_pic_2(self):
  141. pp_bg = PictureProcessing(r"{}\2.jpg".format(self.root))
  142. font = ImageFont.truetype(
  143. r"resources\ttf\puhui\Regular.ttf", 24
  144. ) # 设计理念
  145. design_text = self.get_text_value("设计理念")
  146. pp_bg.get_text_image_advanced(
  147. value=(226, 359),
  148. font=font,
  149. text=design_text,
  150. align="center",
  151. # anchor="ma",
  152. spacing=20,
  153. fill=(88, 52, 28),
  154. return_mode="image",
  155. margins=(0, 0, 0, 0),
  156. )
  157. return pp_bg
  158. # 展示鞋头放大图
  159. def deal_pic_3(self):
  160. pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root))
  161. goods_art_no_list = list(self.data.keys())
  162. pp_jpg_1, pp_png_1 = self.image_one_pic(
  163. return_orign=True,
  164. goods_art_no=goods_art_no_list[0],
  165. name="内里",
  166. )
  167. pp_jpg_1 = pp_jpg_1.resize(value=1600)
  168. pp_png_1 = pp_png_1.resize(value=1600)
  169. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  170. pp_bg = pp_bg.to_overlay_pic_advance(
  171. mode="pixel",
  172. top_img=pp_jpg_1,
  173. base="ne",
  174. value=(100, 0),
  175. top_png_img=pp_png_1,
  176. )
  177. return pp_bg
  178. # 展示后跟放大图
  179. def deal_pic_4(self):
  180. pp_bg = PictureProcessing(r"{}\4.jpg".format(self.root))
  181. return pp_bg
  182. # 展示后跟细节卡片
  183. def deal_pic_5(self):
  184. pp_bg = PictureProcessing(r"{}\5.jpg".format(self.root))
  185. return pp_bg
  186. # "心动"设计亮点,展示旋转的侧视图
  187. def deal_pic_6(self):
  188. pp_bg = PictureProcessing(r"{}\6.jpg".format(self.root))
  189. goods_art_no_list = list(self.data.keys())
  190. pp_jpg_1, pp_png_1 = self.image_one_pic(
  191. return_orign=True,
  192. goods_art_no=goods_art_no_list[0],
  193. name="俯视",
  194. )
  195. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width/1.4)
  196. pp_png_1 = pp_png_1.resize(value=pp_bg.width / 1.4)
  197. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  198. pp_bg = pp_bg.to_overlay_pic_advance(
  199. mode="pixel",
  200. top_img=pp_jpg_1,
  201. base="center",
  202. value=(0, 0),
  203. top_png_img=pp_png_1,
  204. )
  205. return pp_bg
  206. # 产品展示,帮面等等
  207. def deal_pic_7(self):
  208. pp_bg = PictureProcessing(r"{}\7.jpg".format(self.root))
  209. goods_art_no_list = list(self.data.keys())
  210. pp_jpg_1, pp_png_1 = self.image_one_pic(
  211. return_orign=True,
  212. goods_art_no=goods_art_no_list[0],
  213. name="俯视",
  214. )
  215. pp_jpg_1 = pp_jpg_1.resize(value=500)
  216. pp_png_1 = pp_png_1.resize(value=500)
  217. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  218. pp_bg = pp_bg.to_overlay_pic_advance(
  219. mode="pixel",
  220. top_img=pp_jpg_1,
  221. base="ne",
  222. value=(200, 578),
  223. top_png_img=pp_png_1,
  224. )
  225. font = ImageFont.truetype(
  226. r"resources\ttf\puhui\Medium.ttf", 24
  227. ) # 设计理念
  228. font_hei = ImageFont.truetype(r"resources\ttf\simhei.ttf", 24) # 设计理念
  229. bangmian = self.get_text_value("帮面")
  230. neili = self.get_text_value("内里")
  231. xiedi = self.get_text_value("鞋底")
  232. xiedian = self.get_text_value("鞋垫")
  233. xiekuan = self.get_text_value("鞋宽")
  234. banggao = self.get_text_value("帮高")
  235. gengao = self.get_text_value("跟高")
  236. pp_bg.get_text_image_advanced(
  237. value=(230, 346),
  238. font=font,
  239. text=bangmian,
  240. align="left",
  241. # anchor="ma",
  242. spacing=5,
  243. fill=(60, 40, 29),
  244. return_mode="image",
  245. margins=(0, 0, 0, 0),
  246. )
  247. pp_bg.get_text_image_advanced(
  248. value=(551, 346),
  249. font=font,
  250. text=neili,
  251. align="left",
  252. # anchor="ma",
  253. spacing=5,
  254. fill=(60, 40, 29),
  255. return_mode="image",
  256. margins=(0, 0, 0, 0),
  257. )
  258. pp_bg.get_text_image_advanced(
  259. value=(230, 456),
  260. font=font,
  261. text=xiedi,
  262. align="left",
  263. # anchor="ma",
  264. spacing=5,
  265. fill=(60, 40, 29),
  266. return_mode="image",
  267. margins=(0, 0, 0, 0),
  268. )
  269. pp_bg.get_text_image_advanced(
  270. value=(551, 456),
  271. font=font,
  272. text=xiedian,
  273. align="left",
  274. # anchor="ma",
  275. spacing=5,
  276. fill=(60, 40, 29),
  277. return_mode="image",
  278. margins=(0, 0, 0, 0),
  279. )
  280. pp_bg.get_text_image_advanced(
  281. value=(64, 901),
  282. font=font_hei,
  283. text=xiekuan,
  284. align="left",
  285. # anchor="ma",
  286. spacing=5,
  287. fill=(60, 40, 29),
  288. return_mode="image",
  289. margins=(0, 0, 0, 0),
  290. )
  291. pp_bg.get_text_image_advanced(
  292. value=(621, 650),
  293. font=font_hei,
  294. text=banggao,
  295. align="left",
  296. # anchor="ma",
  297. spacing=5,
  298. fill=(60, 40, 29),
  299. return_mode="image",
  300. margins=(0, 0, 0, 0),
  301. )
  302. pp_bg.get_text_image_advanced(
  303. value=(621, 752),
  304. font=font_hei,
  305. text=gengao,
  306. align="left",
  307. # anchor="ma",
  308. spacing=5,
  309. fill=(60, 40, 29),
  310. return_mode="image",
  311. margins=(0, 0, 0, 0),
  312. )
  313. return pp_bg
  314. # 功能展示与卖点
  315. def deal_pic_8(self):
  316. detailed_images = []
  317. detailed_images.append(PictureProcessing(r"{}\8.jpg".format(self.root)))
  318. # goods_art_no_list = list(self.data.keys())
  319. # goods_art_no = goods_art_no_list[0]
  320. # color_name_list = ["侧视", "鞋底", "俯视"]
  321. # font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 42) # 卖点标题1
  322. # font_2 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 32) # 卖点标题2
  323. # font_3 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 26) # 卖点描述1
  324. # # =====卖点1,展示后跟========
  325. # for color_name in color_name_list:
  326. # bg = PictureProcessing(r"{}\t (13).png".format(self.root))
  327. # pp_jpg, pp_png = self.image_one_pic(
  328. # return_orign=True,
  329. # goods_art_no=goods_art_no,
  330. # name=color_name,
  331. # )
  332. # temp_bg = PictureProcessing("RGB", (536, 424), (214, 214, 214))
  333. # if color_name == "侧视":
  334. # pp_png = pp_png.resize(value=990)
  335. # temp_bg = temp_bg.paste_img(top_img=pp_png, base="es")
  336. # shoe_paste_base = "wc"
  337. # text_1, text_2 = self.get_text_value("卖点1标题", subsection_len=2)
  338. # text_3 = self.get_text_value("卖点1介绍")
  339. # text_paste_base = "ec"
  340. # text_paste_value = (312, 0)
  341. # if color_name == "鞋底":
  342. # pp_png = pp_png.resize(value=1000)
  343. # temp_bg = temp_bg.paste_img(top_img=pp_png, base="wc", value=(0, 0))
  344. # shoe_paste_base = "ec"
  345. # text_1, text_2 = self.get_text_value("卖点2标题", subsection_len=2)
  346. # text_3 = self.get_text_value("卖点2介绍")
  347. # text_paste_base = "wc"
  348. # text_paste_value = (312, 0)
  349. # if color_name == "俯视":
  350. # pp_png = pp_png.resize(value=1418)
  351. # temp_bg = temp_bg.paste_img(top_img=pp_png, base="cc")
  352. # shoe_paste_base = "wc"
  353. # text_1, text_2 = self.get_text_value("卖点3标题", subsection_len=2)
  354. # text_3 = self.get_text_value("卖点3介绍")
  355. # text_paste_base = "ec"
  356. # text_paste_value = (312, 0)
  357. # # 添加圆角
  358. # temp_bg = temp_bg.radius(circular_pos=(1, 1, 1, 1), value=50)
  359. # # 粘贴到背景上
  360. # temp_bg = temp_bg.paste_img_invert(
  361. # top_img=bg, base=shoe_paste_base, value=(99, 0)
  362. # )
  363. # text_list = []
  364. # # 卖点主标题
  365. # text_list.append(
  366. # {
  367. # "text": text_1,
  368. # "font": font_1,
  369. # "fill": (2, 2, 2),
  370. # "spacing": 0,
  371. # }
  372. # )
  373. # text_list.append(
  374. # {
  375. # "text": text_2,
  376. # "font": font_2,
  377. # "fill": (43, 43, 43),
  378. # "spacing": 10,
  379. # }
  380. # )
  381. # # 主标题
  382. # text_list.append(
  383. # {
  384. # "text": text_3,
  385. # "font": font_3,
  386. # "fill": (165, 165, 165),
  387. # }
  388. # )
  389. # text_image = self.add_text_list(text_list, spacing=15, base="nc")
  390. # if text_image:
  391. # temp_bg = temp_bg.paste_img(
  392. # top_img=text_image,
  393. # base=text_paste_base,
  394. # value=(
  395. # text_paste_value[0] - text_image.width / 2,
  396. # text_paste_value[1],
  397. # ),
  398. # )
  399. # detailed_images.append(temp_bg)
  400. return PictureProcessing(im=self.add_pic(detailed_images))
  401. # 添加尺码表
  402. def deal_pic_9(self):
  403. image_path = r"{}\9.jpg".format(self.root)
  404. return PictureProcessing(image_path)
  405. # 角度展示
  406. def deal_pic_10(self):
  407. detailed_images = []
  408. # 角度展示标题
  409. detailed_images.append(PictureProcessing(r"{}\10.jpg".format(self.root)))
  410. # # 添加颜色名称字体
  411. # font_color = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 30)
  412. # for goods_art_no_dict in self.goods_no_value["货号资料"]:
  413. # color_name = goods_art_no_dict["颜色名称"]
  414. # goods_art_no = goods_art_no_dict["货号"]
  415. # # ====颜色主图
  416. # pp_1 = self.get_overlay_pic_from_dict(
  417. # goods_art_no=goods_art_no, color_name="俯视", bg_color=(255, 255, 255)
  418. # )
  419. # pp_1: PictureProcessing
  420. # pp_1 = pp_1.resize(value=865)
  421. # pp_1 = pp_1.paste_img_invert(
  422. # top_img=PictureProcessing(
  423. # "RGB", (1152, pp_1.height + 100), (255, 255, 255)
  424. # ),
  425. # base="sc",
  426. # )
  427. # # 粘贴颜色名称
  428. # pp_1 = pp_1.get_text_image_advanced(
  429. # value=(90, 50),
  430. # font=font_color,
  431. # text=color_name,
  432. # spacing=1,
  433. # return_mode="image",
  434. # )
  435. # pp_1 = pp_1.paste_img_invert(
  436. # top_img=PictureProcessing("RGB", (1200, pp_1.height), (243, 243, 243)),
  437. # base="cc",
  438. # )
  439. # detailed_images.append(pp_1)
  440. # # 添加处理各个角度
  441. # view_name_list = ["内里", "鞋底", "后跟", "侧视"]
  442. # color_pic_list = []
  443. # for view_name in view_name_list:
  444. # _, pp_png = self.image_one_pic(
  445. # return_orign=True,
  446. # goods_art_no=goods_art_no,
  447. # name=view_name,
  448. # )
  449. # temp_bg = PictureProcessing("RGB", (546, 338), (243, 243, 243))
  450. # # if view_name == "内里":
  451. # # pp_png = pp_png.resize(base_by_box=(temp_bg.width * 0.9, temp_bg.height * 0.9))
  452. # # if view_name == "鞋底":
  453. # # pp_png = pp_png.resize(base_by_box=(temp_bg.width * 0.9, temp_bg.height * 0.9))
  454. # # if view_name == "后跟":
  455. # # pp_png = pp_png.resize(base_by_box=(temp_bg.width * 0.9, temp_bg.height * 0.9))
  456. # # if view_name == "侧视":
  457. # # pp_png = pp_png.resize(base_by_box=(temp_bg.width * 0.9, temp_bg.height * 0.9))
  458. # pp_png = pp_png.resize(
  459. # base_by_box=(temp_bg.width * 0.9, temp_bg.height * 0.9)
  460. # )
  461. # temp_bg = temp_bg.paste_img(top_img=pp_png, base="cc")
  462. # temp_bg = temp_bg.radius(value=30)
  463. # color_pic_list.append(temp_bg)
  464. # # 颜色列表进行等分展示
  465. # all_color_pp = PictureProcessing().horizontal_distribution(
  466. # color_pic_list, bg_width=1114, line_spacing=10, number_per_row=2
  467. # )
  468. # all_color_pp = all_color_pp.paste_img_invert(
  469. # top_img=PictureProcessing(
  470. # "RGB", (1152, all_color_pp.height + 100), (255, 255, 255)
  471. # ),
  472. # base="cc",
  473. # )
  474. # all_color_pp = all_color_pp.paste_img_invert(
  475. # top_img=PictureProcessing(
  476. # "RGB", (1200, all_color_pp.height), (243, 243, 243)
  477. # ),
  478. # base="cc",
  479. # )
  480. # detailed_images.append(all_color_pp)
  481. # # 添加底部圆弧分割线
  482. # b_bg = PictureProcessing("RGB", (1152, 30), (255, 255, 255))
  483. # b_bg = b_bg.radius(circular_pos=(0, 0, 1, 1), value=30)
  484. # b_bg = b_bg.paste_img_invert(
  485. # top_img=PictureProcessing("RGB", (1200, b_bg.height + 50), (243, 243, 243)),
  486. # base="nc",
  487. # )
  488. # detailed_images.append(b_bg)
  489. # # return PictureProcessing(im=self.add_pic(detailed_images))
  490. return self.pp_pic_subsection(
  491. PictureProcessing(im=self.add_pic(detailed_images))
  492. )
  493. # 添加注意事项
  494. def deal_pic_11(self):
  495. image_path = r"{}\11.jpg".format(self.root)
  496. return PictureProcessing(image_path)
  497. def deal_pic_12(self):
  498. image_path = r"{}\12.jpg".format(self.root)
  499. return PictureProcessing(image_path)
  500. def deal_pic_13(self):
  501. image_path = r"{}\13.jpg".format(self.root)
  502. return PictureProcessing(image_path)
  503. def deal_pic_14(self):
  504. image_path = r"{}\14.jpg".format(self.root)
  505. return PictureProcessing(image_path)
  506. def deal_pic_15(self):
  507. image_path = r"{}\15.jpg".format(self.root)
  508. return PictureProcessing(image_path)
  509. def deal_pic_16(self):
  510. image_path = r"{}\16.jpg".format(self.root)
  511. return PictureProcessing(image_path)
  512. def deal_pic_17(self):
  513. image_path = r"{}\17.jpg".format(self.root)
  514. return PictureProcessing(image_path)
  515. def deal_pic_18(self):
  516. image_path = r"{}\18.jpg".format(self.root)
  517. return PictureProcessing(image_path)
  518. def deal_pic_19(self):
  519. image_path = r"{}\19.jpg".format(self.root)
  520. return PictureProcessing(image_path)
  521. def deal_pic_20(self):
  522. detailed_images = []
  523. bg_20 = PictureProcessing(r"{}\20.jpg".format(self.root))
  524. bg_21 = PictureProcessing(r"{}\21.jpg".format(self.root))
  525. bg_22 = PictureProcessing(r"{}\22.jpg".format(self.root))
  526. detailed_images.append(bg_20)
  527. detailed_images.append(bg_21)
  528. detailed_images.append(bg_22)
  529. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  530. if __name__ == "__main__":
  531. d = DetailPicGet(
  532. goods_no="test",
  533. goods_no_value={},
  534. out_put_dir="./output/xinnuo-1",
  535. test=True,
  536. )
  537. d.run_test()