detail_xinnuo1.py 36 KB

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