detail_xinnuo1.py 37 KB

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