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