detail_xinnuo1.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. from ast import mod
  8. import os
  9. import settings
  10. from PIL import ImageFont
  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 = "xinnuo-1"
  27. class DetailPicGet(DetailBase):
  28. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  29. root = r"{}\resources\detail_temp\xinnuo\1".format(os.getcwd())
  30. def __init__(
  31. self,
  32. goods_no,
  33. goods_no_value: dict,
  34. out_put_dir,
  35. windows=None,
  36. test=False,
  37. excel_data=None,
  38. assigned_page_list=None,
  39. ):
  40. super().__init__(
  41. goods_no,
  42. goods_no_value,
  43. out_put_dir,
  44. windows=windows,
  45. excel_data=excel_data,
  46. assigned_page_list=assigned_page_list,
  47. )
  48. self.template_name = template_name
  49. self.root = r"{}\resources\detail_temp\xinnuo\1".format(os.getcwd())
  50. print("run xinnuo-1 ")
  51. self.base_bg_color = (255, 255, 255)
  52. self.base_bg_color_2 = (244, 242, 243)
  53. self.deal_pic_func_list = [
  54. self.deal_pic_1,
  55. self.deal_pic_2,
  56. self.deal_pic_3,
  57. self.deal_pic_4,
  58. self.deal_pic_5,
  59. self.deal_pic_6,
  60. self.deal_pic_7,
  61. self.deal_pic_8,
  62. self.deal_pic_9,
  63. self.deal_pic_10,
  64. self.deal_pic_11,
  65. self.deal_pic_13,
  66. self.deal_pic_17,
  67. self.deal_pic_18,
  68. self.deal_pic_19,
  69. self.deal_pic_20,
  70. self.deal_pic_21,
  71. ]
  72. if test:
  73. # pp = self.generate_font_list_to_pic()
  74. # pp.im.save(r"C:\Users\gymmc\Desktop\细节图示例/字号.png")
  75. # for k, v in self.goods_no_value.items():
  76. # print(k, v)
  77. self.run_test()
  78. else:
  79. self.run_all()
  80. def run_test(self):
  81. detailed_images = []
  82. detailed_images.append(self.deal_pic_1())
  83. detailed_images.append(self.deal_pic_2())
  84. detailed_images.append(self.deal_pic_3())
  85. detailed_images.append(self.deal_pic_4())
  86. detailed_images.append(self.deal_pic_5())
  87. detailed_images.append(self.deal_pic_6())
  88. detailed_images.append(self.deal_pic_7())
  89. detailed_images.append(self.deal_pic_8())
  90. detailed_images.append(self.deal_pic_9())
  91. detailed_images.append(self.deal_pic_10())
  92. detailed_images.append(self.deal_pic_11())
  93. detailed_images.append(self.deal_pic_13())
  94. detailed_images.append(self.deal_pic_17())
  95. detailed_images.append(self.deal_pic_18())
  96. detailed_images.append(self.deal_pic_19())
  97. detailed_images.append(self.deal_pic_20())
  98. detailed_images.append(self.deal_pic_21())
  99. img = self.add_pic(detailed_images)
  100. img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  101. img.show()
  102. # 标题文字展示
  103. def deal_pic_1(self):
  104. pp_bg = PictureProcessing(r"{}\1.jpg".format(self.root),1600)
  105. font_main = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 102) # 设计理念
  106. mainTitle = self.get_text_value("主标题")
  107. subTitle = self.get_text_value("副标题")
  108. pp_bg.get_text_image_advanced(
  109. value=(336, 95),
  110. font=font_main,
  111. text=mainTitle,
  112. align="left",
  113. # anchor="ma",
  114. spacing=5,
  115. fill=(60, 40, 29),
  116. return_mode="image",
  117. margins=(0, 0, 0, 0),
  118. )
  119. font_sub = ImageFont.truetype(
  120. r"resources\ttf\puhui\Bold.ttf", 40
  121. ) # 设计理念
  122. pp_bg.get_text_image_advanced(
  123. value=(82, 95),
  124. font=font_sub,
  125. text=subTitle,
  126. align="left",
  127. # anchor="ma",
  128. spacing=5,
  129. fill=(60, 40, 29),
  130. return_mode="image",
  131. margins=(0, 0, 0, 0),
  132. )
  133. goods_art_no_list = list(self.data.keys())
  134. pp_jpg_1, pp_png_1 = self.image_one_pic(
  135. return_orign=True,
  136. goods_art_no=goods_art_no_list[0],
  137. name="组合",
  138. )
  139. if pp_jpg_1 == None:
  140. print("组合为空")
  141. pp_jpg_1, pp_png_1 = self.image_one_pic(
  142. return_orign=True,
  143. goods_art_no=goods_art_no_list[0],
  144. name="俯视",
  145. )
  146. if self.check_shoe_is_right_by_pixel(im=pp_png_1.im):
  147. pp_jpg_1 = pp_jpg_1.transpose()
  148. pp_png_1 = pp_png_1.transpose()
  149. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width/1.1)
  150. pp_png_1 = pp_png_1.resize(value=pp_bg.width / 1.1)
  151. pp_bg = pp_bg.to_overlay_pic_advance(
  152. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cs", value=(-50, 190)
  153. )
  154. pp_bg = pp_bg.to_overlay_pic_advance(
  155. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cs", value=(50, 130)
  156. )
  157. else:
  158. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width / 1.1)
  159. pp_png_1 = pp_png_1.resize(value=pp_bg.width / 1.1)
  160. pp_bg = pp_bg.to_overlay_pic_advance(
  161. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cs", value=(0, 130)
  162. )
  163. return pp_bg
  164. # 展示鞋头和后跟
  165. def deal_pic_2(self):
  166. pp_bg = PictureProcessing(r"{}\2.jpg".format(self.root), 1600)
  167. font = ImageFont.truetype(
  168. r"resources\ttf\puhui\Regular.ttf", 24
  169. ) # 设计理念
  170. design_text = self.get_text_value("设计理念")
  171. text_bg = PictureProcessing("RGBA", (pp_bg.width, 200), (255,255,255,0))
  172. text_bg = text_bg.get_text_image_advanced(
  173. value=(0, 0),
  174. font=font,
  175. text=design_text,
  176. align="center",
  177. spacing=20,
  178. fill=(88, 52, 28),
  179. return_mode="min_image",
  180. )
  181. pp_bg = pp_bg.paste_img(top_img=text_bg, base="nc", value=(0, 359))
  182. goods_art_no_list = list(self.data.keys())
  183. pp_jpg_1, pp_png_1 = self.image_one_pic(
  184. return_orign=True,
  185. goods_art_no=goods_art_no_list[0],
  186. name="组合2",
  187. )
  188. if pp_jpg_1 == None:
  189. pp_jpg_1, pp_png_1 = self.image_one_pic(
  190. return_orign=True,
  191. goods_art_no=goods_art_no_list[0],
  192. name="俯视",
  193. )
  194. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width)
  195. pp_png_1 = pp_png_1.resize(value=pp_bg.width)
  196. pp_bg = pp_bg.to_overlay_pic_advance(
  197. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cs", value=(0, 315)
  198. )
  199. return pp_bg
  200. # 展示鞋头放大图
  201. def deal_pic_3(self):
  202. pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root),1600)
  203. goods_art_no_list = list(self.data.keys())
  204. pp_jpg_1, pp_png_1 = self.image_one_pic(
  205. return_orign=True,
  206. goods_art_no=goods_art_no_list[0],
  207. name="内里",
  208. )
  209. pp_jpg_1 = pp_jpg_1.resize(value=1400)
  210. pp_png_1 = pp_png_1.resize(value=1400)
  211. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  212. pp_bg = pp_bg.to_overlay_pic_advance(
  213. mode="pixel",
  214. top_img=pp_jpg_1,
  215. base="sw",
  216. value=(-pp_bg.width + 100, 280),
  217. top_png_img=pp_png_1,
  218. )
  219. return pp_bg
  220. # 展示后跟放大图
  221. def deal_pic_4(self):
  222. pp_bg = PictureProcessing(r"{}\4.jpg".format(self.root))
  223. return pp_bg
  224. # 展示后跟细节卡片
  225. def deal_pic_5(self):
  226. pp_bg = PictureProcessing(r"{}\5.jpg".format(self.root))
  227. return pp_bg
  228. # "心动"设计亮点,展示旋转的侧视图
  229. def deal_pic_6(self):
  230. pp_bg = PictureProcessing(r"{}\6.jpg".format(self.root))
  231. goods_art_no_list = list(self.data.keys())
  232. goods_art = goods_art_no_list[0]
  233. pp_jpg_1, pp_png_1 = self.image_one_pic(
  234. return_orign=True,
  235. goods_art_no=goods_art,
  236. name="组合3",
  237. )
  238. if pp_jpg_1 == None:
  239. pp_jpg_1, pp_png_1 = self.image_one_pic(
  240. return_orign=True,
  241. goods_art_no=goods_art,
  242. name="俯视",
  243. )
  244. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width/1.4)
  245. pp_png_1 = pp_png_1.resize(value=pp_bg.width / 1.4)
  246. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  247. pp_bg = pp_bg.to_overlay_pic_advance(
  248. mode="pixel",
  249. top_img=pp_jpg_1,
  250. base="center",
  251. value=(0, 0),
  252. top_png_img=pp_png_1,
  253. )
  254. return pp_bg
  255. # 产品展示,帮面等等
  256. def deal_pic_7(self):
  257. pp_bg = PictureProcessing(r"{}\7.jpg".format(self.root))
  258. goods_art_no_list = list(self.data.keys())
  259. pp_jpg_1, pp_png_1 = self.image_one_pic(
  260. return_orign=True,
  261. goods_art_no=goods_art_no_list[0],
  262. name="俯视",
  263. )
  264. pp_jpg_1 = pp_jpg_1.resize(value=500)
  265. pp_png_1 = pp_png_1.resize(value=500)
  266. # pp_bg = pp_bg.paste_img(top_img=shoe_bg, value=(0, 0), base="nw")
  267. pp_bg = pp_bg.to_overlay_pic_advance(
  268. mode="pixel",
  269. top_img=pp_jpg_1,
  270. base="sw",
  271. value=(123, 237),
  272. top_png_img=pp_png_1,
  273. )
  274. font = ImageFont.truetype(
  275. r"resources\ttf\puhui\Medium.ttf", 24
  276. ) # 设计理念
  277. font_hei = ImageFont.truetype(r"resources\ttf\simhei.ttf", 24) # 设计理念
  278. bangmian = self.get_text_value("帮面")
  279. neili = self.get_text_value("内里")
  280. xiedi = self.get_text_value("鞋底")
  281. xiedian = self.get_text_value("鞋垫")
  282. xiekuan = self.get_text_value("鞋宽")
  283. banggao = self.get_text_value("帮高")
  284. gengao = self.get_text_value("跟高")
  285. pp_bg.get_text_image_advanced(
  286. value=(230, 351),
  287. font=font,
  288. text=bangmian,
  289. align="left",
  290. # anchor="ma",
  291. spacing=5,
  292. fill=(60, 40, 29),
  293. return_mode="image",
  294. margins=(0, 0, 0, 0),
  295. )
  296. pp_bg.get_text_image_advanced(
  297. value=(551, 351),
  298. font=font,
  299. text=neili,
  300. align="left",
  301. # anchor="ma",
  302. spacing=5,
  303. fill=(60, 40, 29),
  304. return_mode="image",
  305. margins=(0, 0, 0, 0),
  306. )
  307. pp_bg.get_text_image_advanced(
  308. value=(230, 461),
  309. font=font,
  310. text=xiedi,
  311. align="left",
  312. # anchor="ma",
  313. spacing=5,
  314. fill=(60, 40, 29),
  315. return_mode="image",
  316. margins=(0, 0, 0, 0),
  317. )
  318. pp_bg.get_text_image_advanced(
  319. value=(551, 461),
  320. font=font,
  321. text=xiedian,
  322. align="left",
  323. # anchor="ma",
  324. spacing=5,
  325. fill=(60, 40, 29),
  326. return_mode="image",
  327. margins=(0, 0, 0, 0),
  328. )
  329. pp_bg.get_text_image_advanced(
  330. value=(64, 901),
  331. font=font_hei,
  332. text=f"鞋宽\n{xiekuan}",
  333. align="left",
  334. # anchor="ma",
  335. spacing=5,
  336. fill=(60, 40, 29),
  337. return_mode="image",
  338. margins=(0, 0, 0, 0),
  339. )
  340. pp_bg.get_text_image_advanced(
  341. value=(621, 650),
  342. font=font_hei,
  343. text=f"帮高\n{banggao}",
  344. align="left",
  345. # anchor="ma",
  346. spacing=5,
  347. fill=(60, 40, 29),
  348. return_mode="image",
  349. margins=(0, 0, 0, 0),
  350. )
  351. pp_bg.get_text_image_advanced(
  352. value=(621, 752),
  353. font=font_hei,
  354. text=f"跟高\n{gengao}",
  355. align="left",
  356. # anchor="ma",
  357. spacing=5,
  358. fill=(60, 40, 29),
  359. return_mode="image",
  360. margins=(0, 0, 0, 0),
  361. )
  362. return pp_bg
  363. # 功能展示与卖点
  364. def deal_pic_8(self):
  365. detailed_images = []
  366. pp_bg = PictureProcessing(r"{}\7.jpg".format(self.root))
  367. pp_bg_circle = PictureProcessing(r"{}\bg_circle.png".format(self.root))
  368. # detailed_images.append(pp_bg)
  369. goods_art_no_list = list(self.data.keys())
  370. all_color_name = []
  371. bg_color = (254, 249, 245)
  372. text_color = (70, 48, 41)
  373. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 25)
  374. goods_art_images = []
  375. total_height = 0
  376. for index, goods_art_no in enumerate(goods_art_no_list):
  377. pp_jpg,pp_png = self.image_one_pic(
  378. goods_art_no=goods_art_no,
  379. name="侧视",
  380. return_orign=True,
  381. )
  382. if pp_jpg is None:
  383. continue
  384. pp_jpg = pp_jpg.resize(value=pp_bg.width / 2.5)
  385. pp_png = pp_png.resize(value=pp_bg.width / 2.5)
  386. color_name = self.goods_no_value["货号资料"][index]["颜色名称"]
  387. all_color_name.append(color_name)
  388. text_bg = PictureProcessing("RGBA", (pp_jpg.width, 50), (255,255,255,0))
  389. text_bg = text_bg.get_text_image_advanced(
  390. value=(0, 0),
  391. font=font,
  392. text="● {}".format(color_name),
  393. align="center",
  394. # anchor="mm",
  395. spacing=5,
  396. fill=text_color,
  397. return_mode="image",
  398. margins=(0, 0, 0, 0),
  399. )
  400. _bg = PictureProcessing(
  401. "RGB",
  402. (pp_bg.width / 2, pp_jpg.height+200),
  403. bg_color,
  404. )
  405. pp_bg_circle = pp_bg_circle.resize(value=_bg.width/2)
  406. _bg.paste_img(top_img=pp_bg_circle, base="center")
  407. if (index+1) == 1:
  408. total_height += _bg.height
  409. if (index + 1) % 2 != 0 and (index + 1) != 1:
  410. total_height += _bg.height
  411. _bg = _bg.to_overlay_pic_advance(top_img=pp_jpg,top_png_img=pp_png, base="center")
  412. _bg = _bg.paste_img(
  413. top_img=text_bg, value=(pp_jpg.width / 2, pp_jpg.height+150)
  414. )
  415. goods_art_images.append(_bg)
  416. rows = 2
  417. shoes_bg = PictureProcessing(
  418. ).horizontal_distribution(
  419. pp_list=goods_art_images,
  420. bg_width=pp_bg.width,
  421. margins=(0, 0, 0, 0),
  422. line_spacing=0,
  423. number_per_row=rows,
  424. )
  425. main_bg = PictureProcessing(
  426. "RGB",
  427. (pp_bg.width, total_height),
  428. bg_color,
  429. )
  430. main_bg.paste_img(top_img=shoes_bg)
  431. detailed_images.append(main_bg)
  432. return PictureProcessing(im=self.add_pic(detailed_images))
  433. # 添加尺码表
  434. def deal_pic_9(self):
  435. image_path = r"{}\9.jpg".format(self.root)
  436. return PictureProcessing(image_path)
  437. # 角度展示
  438. def deal_pic_10(self):
  439. detailed_images = []
  440. image_path = r"{}\10.jpg".format(self.root)
  441. pp_bg = PictureProcessing(image_path,1600)
  442. # pp_arrow = PictureProcessing(r"{}\arrow.png".format(self.root))
  443. goods_art_no_list = list(self.data.keys())
  444. pp_jpg_1, pp_png_1 = self.image_one_pic(
  445. return_orign=True,
  446. goods_art_no=goods_art_no_list[0],
  447. name="俯视",
  448. )
  449. pp_jpg_1 = pp_jpg_1.resize(value=1400)
  450. pp_png_1 = pp_png_1.resize(value=1400)
  451. bg_circl = PictureProcessing("RGB", (300, 300), (239, 208, 177))
  452. bg_circl_paste = PictureProcessing("RGB", (290, 290), (239, 208, 177))
  453. # bg_circl_paste.paste_img(top_img=pp_jpg_1, base="center")
  454. bg_circl_paste = bg_circl_paste.radius(value=145, circular_pos=(1, 1, 1, 1))
  455. bg_circl = bg_circl.radius(value=150, circular_pos=(1, 1, 1, 1))
  456. bg_circl = bg_circl.paste_img(top_img=bg_circl_paste, base="center")
  457. # bg_circl = bg_circl.paste_img(top_img=pp_arrow, base="nc")
  458. pp_bg = pp_bg.paste_img(top_img=bg_circl, base="nw", value=(63, 493))
  459. pp_bg = pp_bg.to_overlay_pic_advance(
  460. mode="pixel",
  461. top_img=pp_jpg_1,
  462. base="nw",
  463. value=(0, pp_bg.height - pp_jpg_1.height),
  464. top_png_img=pp_png_1,
  465. )
  466. font_main = ImageFont.truetype(
  467. r"resources\ttf\puhui\Medium.ttf", 58
  468. ) # 设计理念
  469. mainTitle = self.get_text_value("细节亮点主标题")
  470. subTitle = self.get_text_value("细节亮点副标题")
  471. pp_bg.get_text_image_advanced(
  472. value=(pp_bg.width / 2, 219),
  473. font=font_main,
  474. text=mainTitle,
  475. align="center",
  476. anchor="ma",
  477. spacing=5,
  478. fill=(60, 40, 29),
  479. return_mode="image",
  480. margins=(0, 0, 0, 0),
  481. )
  482. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 36) # 设计理念
  483. pp_bg.get_text_image_advanced(
  484. value=(pp_bg.width / 2, 313),
  485. font=font_sub,
  486. text=subTitle,
  487. align="center",
  488. anchor="ma",
  489. spacing=5,
  490. fill=(60, 40, 29),
  491. return_mode="image",
  492. margins=(0, 0, 0, 0),
  493. )
  494. detailed_images.append(pp_bg)
  495. return self.pp_pic_subsection(
  496. PictureProcessing(im=self.add_pic(detailed_images))
  497. )
  498. # 添加注意事项
  499. def deal_pic_11(self):
  500. """
  501. bg_12_image_path = r"{}\12.jpg".format(self.root)
  502. bg_12 = PictureProcessing(bg_12_image_path)
  503. detailed_images.append(bg_12)
  504. """
  505. detailed_images = []
  506. image_path = r"{}\11.png".format(self.root)
  507. pp_bg = PictureProcessing(image_path, 1600)
  508. pp_bg_backend = PictureProcessing(
  509. "RGB", (pp_bg.width, pp_bg.height), (245, 235, 226)
  510. )
  511. goods_art_no_list = list(self.data.keys())
  512. pp_jpg_1, pp_png_1 = self.image_one_pic(
  513. return_orign=True,
  514. goods_art_no=goods_art_no_list[0],
  515. name="俯视",
  516. )
  517. pp_jpg_1 = pp_jpg_1.resize(value=1800)
  518. pp_png_1 = pp_png_1.resize(value=1800)
  519. pp_bg_backend = pp_bg_backend.to_overlay_pic_advance(
  520. mode="pixel",
  521. top_img=pp_jpg_1,
  522. base="cs",
  523. value=(0, -100),
  524. top_png_img=pp_png_1,
  525. )
  526. font_main = ImageFont.truetype(
  527. r"resources\ttf\puhui\Medium.ttf", 58
  528. ) # 设计理念
  529. pp_bg_backend.get_text_image_advanced(
  530. value=(pp_bg.width / 2, 219),
  531. font=font_main,
  532. text="经 典 系 带",
  533. align="center",
  534. anchor="ma",
  535. spacing=5,
  536. fill=(107, 70, 61),
  537. return_mode="image",
  538. margins=(0, 0, 0, 0),
  539. )
  540. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 36) # 设计理念
  541. pp_bg_backend.get_text_image_advanced(
  542. value=(pp_bg.width / 2, 313),
  543. font=font_sub,
  544. text="松 紧 自 由 调 节",
  545. align="center",
  546. anchor="ma",
  547. spacing=5,
  548. fill=(107, 70, 61),
  549. return_mode="image",
  550. margins=(0, 0, 0, 0),
  551. )
  552. pp_bg_backend.paste_img(top_img=pp_bg,base="center")
  553. detailed_images.append(pp_bg_backend)
  554. # bg_12_image_path = r"{}\12.jpg".format(self.root)
  555. # bg_12 = PictureProcessing(bg_12_image_path)
  556. # detailed_images.append(bg_12)
  557. return self.pp_pic_subsection(
  558. PictureProcessing(im=self.add_pic(detailed_images))
  559. )
  560. def deal_pic_13(self):
  561. detailed_images = []
  562. image_path = r"{}\12.jpg".format(self.root)
  563. pp_bg = PictureProcessing(image_path,1600)
  564. detailed_images.append(pp_bg)
  565. radius_top = PictureProcessing(
  566. "RGB", (pp_bg.width * 0.75, 40), (255, 255, 255)
  567. ).radius(value=30, circular_pos=(1, 1, 0, 0))
  568. radius_top_bg = PictureProcessing("RGB", (pp_bg.width, 40), (253, 246, 237))
  569. image_list = ["俯视","侧视","后跟"]
  570. for item in image_list:
  571. pp_bg_background = PictureProcessing(
  572. "RGB", (pp_bg.width, 800), (253, 246, 237)
  573. )
  574. pp_bg_radius = PictureProcessing(
  575. "RGB", (pp_bg.width * 0.85, 800), (255, 255, 255)
  576. )
  577. radius_top_bg = radius_top_bg.paste_img(top_img=radius_top, base="cc")
  578. detailed_images.append(radius_top_bg)
  579. goods_art_no_list = list(self.data.keys())
  580. pp_jpg_1, pp_png_1 = self.image_one_pic(
  581. return_orign=True,
  582. goods_art_no=goods_art_no_list[0],
  583. name=item,
  584. )
  585. if item =="俯视":
  586. if self.check_shoe_is_right_by_pixel(im=pp_png_1.im):
  587. pp_jpg_1 = pp_jpg_1.transpose()
  588. pp_png_1 = pp_png_1.transpose()
  589. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg_radius.width / 1.3)
  590. pp_png_1 = pp_png_1.resize(value=pp_bg_radius.width / 1.3)
  591. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  592. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(-50, 0)
  593. )
  594. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  595. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(50, 60)
  596. )
  597. if item == "侧视":
  598. if self.check_shoe_is_right_by_pixel(im=pp_png_1.im):
  599. pp_jpg_1 = pp_jpg_1.transpose()
  600. pp_png_1 = pp_png_1.transpose()
  601. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg_radius.width / 1.3)
  602. pp_png_1 = pp_png_1.resize(value=pp_bg_radius.width / 1.3)
  603. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  604. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(60, 0)
  605. )
  606. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  607. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(-60, 0)
  608. )
  609. if item == "后跟":
  610. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg_radius.width / 2.3)
  611. pp_png_1 = pp_png_1.resize(value=pp_bg_radius.width / 2.3)
  612. pp_jpg_1 = pp_jpg_1.transpose()
  613. pp_png_1 = pp_png_1.transpose()
  614. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  615. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(130, 0)
  616. )
  617. pp_jpg_1 = pp_jpg_1.transpose()
  618. pp_png_1 = pp_png_1.transpose()
  619. pp_bg_radius = pp_bg_radius.to_overlay_pic_advance(
  620. top_img=pp_jpg_1, top_png_img=pp_png_1, base="cc", value=(-130, 0)
  621. )
  622. pp_bg_radius = pp_bg_radius.radius(value=30, circular_pos=(1, 1, 1, 1))
  623. pp_bg_background.paste_img(top_img=pp_bg_radius, base="cc", value=(0, 0))
  624. detailed_images.append(pp_bg_background)
  625. radius_bottom = PictureProcessing(
  626. "RGB", (pp_bg.width * 0.75, 40), (255, 255, 255)
  627. ).radius(value=30, circular_pos=(0, 0, 1, 1))
  628. radius_bottom_bg = PictureProcessing("RGB", (pp_bg.width, 40), (253, 246, 237))
  629. radius_bottom_bg = radius_bottom_bg.paste_img(top_img=radius_bottom, base="cc")
  630. detailed_images.append(radius_bottom_bg)
  631. detailed_images.append(
  632. PictureProcessing("RGB", (pp_bg.width, 50), (253, 246, 237))
  633. )
  634. return self.pp_pic_subsection(
  635. PictureProcessing(im=self.add_pic(detailed_images))
  636. )
  637. def deal_pic_17(self):
  638. # 产品细节
  639. image_path = r"{}\17.jpg".format(self.root)
  640. image_path_1 = r"{}\17_1.png".format(self.root)
  641. detailed_images = []
  642. pp_bg_1 = PictureProcessing(image_path_1)
  643. pp_bg = PictureProcessing(image_path)
  644. goods_art_no_list = list(self.data.keys())
  645. pp_jpg_1, pp_png_1 = self.image_one_pic(
  646. return_orign=True,
  647. goods_art_no=goods_art_no_list[0],
  648. name="俯视",
  649. )
  650. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width+100)
  651. pp_png_1 = pp_png_1.resize(value=pp_bg.width + 100)
  652. pp_bg = pp_bg.to_overlay_pic_advance(
  653. mode="pixel",
  654. top_img=pp_jpg_1,
  655. base="cs",
  656. value=(0, 0),
  657. top_png_img=pp_png_1,
  658. )
  659. mainTitle = self.get_text_value("艺-主标题")
  660. subTitle = self.get_text_value("艺-副标题")
  661. font_main = ImageFont.truetype(
  662. r"resources\ttf\puhui\Medium.ttf", 30
  663. ) # 设计理念
  664. pp_bg.get_text_image_advanced(
  665. value=(113, 545),
  666. font=font_main,
  667. text=mainTitle,
  668. align="left",
  669. # anchor="ma",
  670. spacing=5,
  671. fill=(60, 40, 29),
  672. return_mode="image",
  673. margins=(0, 0, 0, 0),
  674. )
  675. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 24) # 设计理念
  676. pp_bg.get_text_image_advanced(
  677. value=(113, 602),
  678. font=font_sub,
  679. text=subTitle,
  680. align="left",
  681. # anchor="ma",
  682. spacing=5,
  683. fill=(60, 40, 29),
  684. return_mode="image",
  685. margins=(0, 0, 0, 0),
  686. )
  687. pp_bg.paste_img(top_img=pp_bg_1)
  688. detailed_images.append(pp_bg)
  689. return self.pp_pic_subsection(
  690. PictureProcessing(im=self.add_pic(detailed_images))
  691. )
  692. def deal_pic_18(self):
  693. image_path = r"{}\18.jpg".format(self.root)
  694. image_path_1 = r"{}\18_1.png".format(self.root)
  695. detailed_images = []
  696. pp_bg_1 = PictureProcessing(image_path_1)
  697. pp_bg = PictureProcessing(image_path)
  698. goods_art_no_list = list(self.data.keys())
  699. pp_jpg_1, pp_png_1 = self.image_one_pic(
  700. return_orign=True,
  701. goods_art_no=goods_art_no_list[0],
  702. name="侧视",
  703. )
  704. pp_jpg_1 = pp_jpg_1.resize(value=1400)
  705. pp_png_1 = pp_png_1.resize(value=1400)
  706. pp_bg = pp_bg.to_overlay_pic_advance(
  707. mode="pixel",
  708. top_img=pp_jpg_1,
  709. base="cs",
  710. value=(-pp_jpg_1.width/3, 0),
  711. top_png_img=pp_png_1,
  712. )
  713. mainTitle = self.get_text_value("跟-主标题")
  714. subTitle = self.get_text_value("跟-副标题")
  715. gengao = self.get_text_value("跟高")
  716. font_main = ImageFont.truetype(
  717. r"resources\ttf\puhui\Medium.ttf", 30
  718. ) # 设计理念
  719. pp_bg.get_text_image_advanced(
  720. value=(441, 220),
  721. font=font_main,
  722. text=mainTitle,
  723. align="right",
  724. # anchor="rs",
  725. spacing=5,
  726. fill=(60, 40, 29),
  727. return_mode="image",
  728. margins=(0, 0, 0, 0),
  729. )
  730. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 24) # 设计理念
  731. pp_bg.get_text_image_advanced(
  732. value=(441, 272),
  733. font=font_sub,
  734. text=subTitle,
  735. align="right",
  736. # anchor="ls",
  737. spacing=5,
  738. fill=(60, 40, 29),
  739. return_mode="image",
  740. margins=(0, 0, 0, 0),
  741. )
  742. pp_bg.get_text_image_advanced(
  743. value=(605, 648),
  744. font=font_main,
  745. text=gengao,
  746. align="right",
  747. # anchor="ls",
  748. spacing=5,
  749. fill=(60, 40, 29),
  750. return_mode="image",
  751. margins=(0, 0, 0, 0),
  752. )
  753. pp_bg.paste_img(top_img=pp_bg_1)
  754. detailed_images.append(pp_bg)
  755. return self.pp_pic_subsection(
  756. PictureProcessing(im=self.add_pic(detailed_images))
  757. )
  758. def deal_pic_19(self):
  759. detailed_images = []
  760. image_path = r"{}\19.jpg".format(self.root)
  761. pp_bg = PictureProcessing(image_path)
  762. # 鞋底
  763. goods_art_no_list = list(self.data.keys())
  764. pp_jpg_1, pp_png_1 = self.image_one_pic(
  765. return_orign=True,
  766. goods_art_no=goods_art_no_list[0],
  767. name="鞋底",
  768. )
  769. pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width)
  770. pp_png_1 = pp_png_1.resize(value=pp_bg.width)
  771. pp_bg = pp_bg.to_overlay_pic_advance(
  772. mode="pixel",
  773. top_img=pp_jpg_1,
  774. base="center",
  775. value=(0, 200),
  776. top_png_img=pp_png_1,
  777. )
  778. mainTitle = self.get_text_value("底-主标题")
  779. subTitle = self.get_text_value("底-副标题")
  780. font_main = ImageFont.truetype(
  781. r"resources\ttf\puhui\Medium.ttf", 30
  782. ) # 设计理念
  783. pp_bg.get_text_image_advanced(
  784. value=(114, 259),
  785. font=font_main,
  786. text=mainTitle,
  787. align="left",
  788. # anchor="rs",
  789. spacing=5,
  790. fill=(60, 40, 29),
  791. return_mode="image",
  792. margins=(0, 0, 0, 0),
  793. )
  794. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 24) # 设计理念
  795. pp_bg.get_text_image_advanced(
  796. value=(114, 311),
  797. font=font_sub,
  798. text=subTitle,
  799. align="left",
  800. # anchor="ls",
  801. spacing=5,
  802. fill=(60, 40, 29),
  803. return_mode="image",
  804. margins=(0, 0, 0, 0),
  805. )
  806. # return PictureProcessing(image_path)
  807. detailed_images.append(pp_bg)
  808. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  809. def deal_pic_20(self):
  810. detailed_images = []
  811. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30) # 设计理念
  812. pp_bg = PictureProcessing(r"{}\20.jpg".format(self.root))
  813. detailed_images.append(pp_bg)
  814. goods_art_no_list = list(self.data.keys())
  815. for item in goods_art_no_list:
  816. radius_top_bg = PictureProcessing(
  817. "RGB", (pp_bg.width, 1048), (253, 246, 237)
  818. )
  819. bg_radius = PictureProcessing(
  820. "RGB",
  821. (pp_bg.width * 0.85, radius_top_bg.height * 0.85),
  822. (255, 255, 255),
  823. )
  824. pp_jpg_1, pp_png_1 = self.image_one_pic(
  825. return_orign=True,
  826. goods_art_no=item,
  827. name="俯视",
  828. )
  829. pp_jpg_1 = pp_jpg_1.resize(value=bg_radius.width/1.3)
  830. pp_png_1 = pp_png_1.resize(value=bg_radius.width /1.3)
  831. bg_radius = bg_radius.to_overlay_pic_advance(
  832. top_img=pp_jpg_1, top_png_img=pp_png_1, base="nc",value=(0,150)
  833. )
  834. bg_radius = bg_radius.radius(value=30)
  835. text_bg = PictureProcessing(
  836. "RGBA", (pp_jpg_1.width, 50), (255, 255, 255, 0)
  837. )
  838. text_bg = text_bg.get_text_image_advanced(
  839. value=(0, 0),
  840. font=font,
  841. text="斜面展示",
  842. align="center",
  843. # anchor="mm",
  844. spacing=5,
  845. fill=(70, 45, 36),
  846. return_mode="min_image",
  847. margins=(0, 0, 0, 0),
  848. )
  849. _bg = PictureProcessing(
  850. "RGBA",
  851. (pp_bg.width / 2, pp_png_1.height + 200),
  852. (255, 255, 255,0),
  853. )
  854. _bg.paste_img(top_img=text_bg, base="center",value=(0,50))
  855. bg_radius.paste_img(top_img=_bg, base="center")
  856. radius_top_bg = radius_top_bg.paste_img(top_img=bg_radius, base="center")
  857. pp_jpg_1, pp_png_1 = self.image_one_pic(
  858. return_orign=True,
  859. goods_art_no=item,
  860. name="内里",
  861. )
  862. pp_jpg_1 = pp_jpg_1.resize(value=bg_radius.width / 2)
  863. pp_png_1 = pp_png_1.resize(value=bg_radius.width / 2)
  864. bg_radius = bg_radius.to_overlay_pic_advance(
  865. top_img=pp_jpg_1, top_png_img=pp_png_1, base="sw", value=(0, 150)
  866. )
  867. bg_radius = bg_radius.radius(value=30)
  868. text_bg = PictureProcessing(
  869. "RGBA", (pp_jpg_1.width, 50), (255, 255, 255, 0)
  870. )
  871. text_bg = text_bg.get_text_image_advanced(
  872. value=(0, 0),
  873. font=font,
  874. text="鞋面展示",
  875. align="center",
  876. # anchor="mm",
  877. spacing=5,
  878. fill=(70, 45, 36),
  879. return_mode="min_image",
  880. margins=(0, 0, 0, 0),
  881. )
  882. _bg = PictureProcessing(
  883. "RGBA",
  884. (pp_bg.width / 2, pp_png_1.height + 150),
  885. (255, 255, 255, 0),
  886. )
  887. _bg.paste_img(top_img=text_bg, base="center")
  888. bg_radius.paste_img(top_img=_bg, base="sw",value=(-50,-20))
  889. radius_top_bg = radius_top_bg.paste_img(top_img=bg_radius, base="center")
  890. pp_jpg_1, pp_png_1 = self.image_one_pic(
  891. return_orign=True,
  892. goods_art_no=item,
  893. name="鞋底",
  894. )
  895. pp_jpg_1 = pp_jpg_1.resize(value=bg_radius.width / 2)
  896. pp_png_1 = pp_png_1.resize(value=bg_radius.width / 2)
  897. bg_radius = bg_radius.to_overlay_pic_advance(
  898. top_img=pp_jpg_1, top_png_img=pp_png_1, base="es", value=(0, 150)
  899. )
  900. bg_radius = bg_radius.radius(value=30)
  901. text_bg = PictureProcessing(
  902. "RGBA", (pp_jpg_1.width, 50), (255, 255, 255, 0)
  903. )
  904. text_bg = text_bg.get_text_image_advanced(
  905. value=(0, 0),
  906. font=font,
  907. text="鞋底展示",
  908. align="center",
  909. # anchor="mm",
  910. spacing=5,
  911. fill=(70, 45, 36),
  912. return_mode="min_image",
  913. margins=(0, 0, 0, 0),
  914. )
  915. _bg = PictureProcessing(
  916. "RGBA",
  917. (pp_bg.width / 2, pp_png_1.height + 150),
  918. (255, 255, 255, 0),
  919. )
  920. _bg.paste_img(top_img=text_bg, base="center")
  921. bg_radius.paste_img(top_img=_bg, base="es", value=(-50, -20))
  922. radius_top_bg = radius_top_bg.paste_img(top_img=bg_radius, base="center")
  923. detailed_images.append(radius_top_bg)
  924. return self.pp_pic_subsection(
  925. PictureProcessing(im=self.add_pic(detailed_images))
  926. )
  927. def deal_pic_21(self):
  928. detailed_images = []
  929. bg_21 = PictureProcessing(r"{}\21.jpg".format(self.root))
  930. detailed_images.append(bg_21)
  931. return self.pp_pic_subsection(
  932. PictureProcessing(im=self.add_pic(detailed_images))
  933. )
  934. if __name__ == "__main__":
  935. d = DetailPicGet(
  936. goods_no="test",
  937. goods_no_value={},
  938. out_put_dir="./output/xinnuo-1",
  939. test=True,
  940. )
  941. d.run_test()