detail_xiaosushuoxie7.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. import settings
  9. from PIL import ImageFont
  10. # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
  11. # from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  12. try:
  13. is_test_plugins = settings.is_test_plugins
  14. except:
  15. is_test_plugins = False
  16. if is_test_plugins:
  17. from custom_plugins.plugins_mode.detail_generate_base import DetailBase
  18. from custom_plugins.plugins_mode.pic_deal import PictureProcessing
  19. else:
  20. from plugins_mode.detail_generate_base import DetailBase
  21. from plugins_mode.pic_deal import PictureProcessing
  22. from PIL import Image, ImageDraw
  23. plugins_name = "详情模板"
  24. company_name_list = ["小苏"]
  25. template_name = "xiaosushuoxie-7"
  26. class DetailPicGet(DetailBase):
  27. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  28. root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd())
  29. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False,excel_data=None,assigned_page_list=None):
  30. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows,excel_data=excel_data,assigned_page_list=assigned_page_list)
  31. self.root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd())
  32. self.template_name = template_name
  33. self.base_bg_color = (236, 226, 211)
  34. self.white_bg_color = (255, 255, 255)
  35. self.black_bg_color = (0, 0, 0)
  36. self.deal_pic_func_list = [
  37. self.deal_pic_1,
  38. self.deal_pic_2,
  39. self.deal_pic_3,
  40. self.deal_pic_4,
  41. self.deal_pic_5,
  42. self.deal_pic_6,
  43. self.deal_pic_7,
  44. self.deal_pic_8,
  45. self.deal_pic_9,
  46. self.deal_pic_10,
  47. self.deal_pic_11,
  48. ]
  49. if test:
  50. self.run_test()
  51. else:
  52. self.run_all()
  53. def run_test(self):
  54. detailed_images = []
  55. detailed_images.append(self.deal_pic_1())
  56. detailed_images.append(self.deal_pic_2())
  57. detailed_images.append(self.deal_pic_3())
  58. detailed_images.append(self.deal_pic_4())
  59. detailed_images.append(self.deal_pic_5())
  60. detailed_images.append(self.deal_pic_6())
  61. detailed_images.append(self.deal_pic_7())
  62. detailed_images.append(self.deal_pic_8())
  63. detailed_images.append(self.deal_pic_9())
  64. detailed_images.append(self.deal_pic_10())
  65. detailed_images.append(self.deal_pic_11())
  66. img = self.add_pic(detailed_images)
  67. img.save(r"{}/{}.jpg".format(self.out_put_dir,self.goods_no, format="JPEG"))
  68. def deal_pic_1(self):
  69. """ 制作主图 """
  70. detailed_images = []
  71. pp_bg = PictureProcessing(r"{}\first_bg.png".format(self.root))
  72. # -------粘贴文字-------
  73. mainTitle = self.get_text_value("主标题")
  74. subTitle = self.get_text_value("副标题")
  75. signTitle = self.get_text_value("签名")
  76. fontMain = ImageFont.truetype(r"resources\ttf\DOUYINSANSBOLD.ttf", 240)
  77. fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 40)
  78. fontSign = ImageFont.truetype(r"resources\ttf\puhui\en\Bold.otf", 40)
  79. main_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  80. main_text_bg = main_text_bg.get_text_image_advanced(
  81. value=(0, 0),
  82. font=fontMain,
  83. text=mainTitle,
  84. align="center",
  85. fill=self.white_bg_color,
  86. spacing=5,
  87. return_mode="min_image",
  88. )
  89. # 副标题
  90. sub_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  91. sub_text_bg = sub_text_bg.get_text_image_advanced(
  92. value=(0, 0),
  93. font=fontSub,
  94. text=subTitle,
  95. align="center",
  96. fill=self.white_bg_color,
  97. spacing=5,
  98. return_mode="min_image",
  99. )
  100. # 签名
  101. sign_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  102. sign_text_bg = sign_text_bg.get_text_image_advanced(
  103. value=(0, 0),
  104. font=fontSign,
  105. text=signTitle,
  106. align="center",
  107. fill=self.white_bg_color,
  108. spacing=5,
  109. return_mode="min_image",
  110. )
  111. pp_bg = pp_bg.paste_img(top_img=main_text_bg,value=(0,208),base='nc')
  112. pp_bg = pp_bg.paste_img(top_img=sub_text_bg,value=(0,470),base='nc')
  113. pp_bg = pp_bg.paste_img(top_img=sign_text_bg,value=(0,57),base='nc')
  114. bottom_bg = PictureProcessing(
  115. r"{}\bolang.png".format(
  116. self.root
  117. )
  118. )
  119. pp_bg.paste_img(top_img=bottom_bg, value=(0, 0),base='cs')
  120. detailed_images.append(pp_bg)
  121. return PictureProcessing(im=self.add_pic(detailed_images))
  122. def deal_pic_2(self):
  123. """
  124. 细节解析
  125. """
  126. # 文字排列
  127. detailed_images = []
  128. top_bg = PictureProcessing(
  129. r"{}\bolang.png".format(
  130. self.root
  131. )
  132. )
  133. # detailed_images.append(top_bg)
  134. designText1 = self.get_text_value("设计理念1")
  135. designText2 = self.get_text_value("设计理念2")
  136. designText3 = self.get_text_value("设计理念3")
  137. fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 60)
  138. centerDesign = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 65)
  139. first_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  140. first_text_bg = first_text_bg.get_text_image_advanced(
  141. value=(0, 0),
  142. font=fontSub,
  143. text=designText1,
  144. align="center",
  145. fill=self.black_bg_color,
  146. return_mode="min_image",
  147. )
  148. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  149. temp_text_bg = temp_text_bg.paste_img(top_img=first_text_bg,value=(0,0),base='cc')
  150. detailed_images.append(temp_text_bg)
  151. second_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  152. second_text_bg = second_text_bg.get_text_image_advanced(
  153. value=(0, 0),
  154. font=centerDesign,
  155. text=designText2,
  156. align="center",
  157. fill=self.black_bg_color,
  158. return_mode="min_image",
  159. )
  160. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  161. temp_text_bg = temp_text_bg.paste_img(top_img=second_text_bg,value=(0,0),base='cc')
  162. detailed_images.append(temp_text_bg)
  163. third_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  164. third_text_bg = third_text_bg.get_text_image_advanced(
  165. value=(0, 0),
  166. font=fontSub,
  167. text=designText3,
  168. align="center",
  169. fill=self.black_bg_color,
  170. return_mode="min_image",
  171. )
  172. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  173. temp_text_bg = temp_text_bg.paste_img(top_img=third_text_bg,value=(0,0),base='cc')
  174. detailed_images.append(temp_text_bg)
  175. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  176. detailed_images.append(temp_text_bg)
  177. # 卡片
  178. pp_list_1 = []
  179. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60)
  180. fontEN = ImageFont.truetype(r"resources\ttf\puhui\en\Medium.otf", 30)
  181. goods_art_no_list = list(self.data.keys())
  182. pp_jpg = self.get_overlay_pic_from_dict(
  183. goods_art_no=goods_art_no_list[0],
  184. color_name="俯视",
  185. bg_color=self.white_bg_color,
  186. )
  187. pp_jpg = pp_jpg.resize(value=840)
  188. text_array = [{"title":self.get_text_value("鞋跟描述")
  189. ,"bottom":"Comfortable heel","position":(-200, 0)},
  190. {"title":self.get_text_value("鞋头描述"),
  191. "position":(200, 0),"bottom":"Versatile Upper"}]
  192. for index, item in enumerate(text_array):
  193. text_bg = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0))
  194. text_bg = text_bg.get_text_image_advanced(
  195. value=(0, 0),
  196. font=font,
  197. text="{}".format(item["title"]),
  198. align="center",
  199. spacing=15,
  200. fill=(255, 255, 255),
  201. return_mode="min_image",
  202. margins=(10, 5, 0, 0),
  203. max_len_one_line=6
  204. )
  205. _bg = PictureProcessing("RGB", (520, 880), (208, 186, 162))
  206. _bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60)
  207. _bg = _bg.paste_img(top_img=text_bg, value=(0, 50),base='nc')
  208. text_bottome = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0))
  209. text_bottome = text_bottome.get_text_image_advanced(
  210. value=(0, 0),
  211. font=fontEN,
  212. text="{}".format(item["bottom"]),
  213. align="center",
  214. spacing=15,
  215. fill=(255, 255, 255),
  216. return_mode="min_image",
  217. margins=(10, 5, 0, 0),
  218. )
  219. _bg = _bg.paste_img(top_img=text_bottome, value=(0, 50),base='cs')
  220. # 第一张图
  221. first_imageBg = PictureProcessing("RGB", (420, 600), self.white_bg_color)
  222. first_imageBg.paste_img(top_img=pp_jpg, value=item["position"], base='cc')
  223. _bg = _bg.paste_img(top_img=first_imageBg, value=(0, 0),base='cc')
  224. pp_list_1.append(_bg)
  225. rows = 2
  226. shoes_bg = PictureProcessing().horizontal_distribution(
  227. pp_list=pp_list_1,
  228. bg_width=top_bg.width,
  229. margins=(0, 0, 50, 50),
  230. line_spacing=60,
  231. number_per_row=rows,
  232. )
  233. detailed_images.append(shoes_bg)
  234. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  235. detailed_images.append(temp_text_bg)
  236. return PictureProcessing(im=self.add_pic(detailed_images))
  237. def deal_pic_3(self):
  238. detailed_images = []
  239. pp_bg = PictureProcessing(
  240. r"{}\template_4.jpg".format(
  241. self.root
  242. )
  243. )
  244. _bg = PictureProcessing("RGB", (pp_bg.width*0.8, pp_bg.height*0.8), self.white_bg_color)
  245. _bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60)
  246. font1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 100)
  247. font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  248. text_bg = PictureProcessing("RGB", (440, 200), (255, 255, 255))
  249. text1 = self.get_text_value("面料FAB1")
  250. if not text1:
  251. text1 = "轻盈透气"
  252. text_bg = text_bg.get_text_image_advanced(
  253. value=(0, 0),
  254. font=font1,
  255. text=text1,
  256. align="left",
  257. spacing=5,
  258. fill=(194, 189, 167),
  259. return_mode="min_image",
  260. )
  261. _bg.paste_img(top_img=text_bg, value=(50, 40),base='nw')
  262. # text2
  263. text2 = self.get_text_value("面料FAB2")
  264. if not text2:
  265. text2 = "(软弹不易累脚)"
  266. text_bg2 = PictureProcessing("RGB", (440, 200), (255, 255, 255))
  267. text_bg2 = text_bg2.get_text_image_advanced(
  268. value=(0, 0),
  269. font=font2,
  270. text=text2,
  271. align="left",
  272. spacing=5,
  273. fill=(194, 189, 167),
  274. return_mode="min_image",
  275. )
  276. _bg.paste_img(top_img=text_bg2, value=(50, 140),base='en')
  277. pp_bg = pp_bg.paste_img(top_img=_bg, value=(0, 0),base='cc')
  278. detailed_images.append(pp_bg)
  279. return PictureProcessing(im=self.add_pic(detailed_images))
  280. def deal_pic_4(self):
  281. # =============设计理念================
  282. detail_images = []
  283. top_bg = PictureProcessing(r"{}\template_5.jpg".format(self.root))
  284. goods_art_no_list = list(self.data.keys())
  285. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  286. goods_art_no=goods_art_no_list[0],
  287. name="俯视",
  288. )
  289. pp_jpg = pp_jpg.resize(value=round(top_bg.width*0.8))
  290. pp_png = pp_png.resize(value=round(top_bg.width*0.8))
  291. top_bg = top_bg.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc",value=(0, 0))
  292. #
  293. textTitle1 = self.get_text_value("材质FAB1")
  294. textTitle2 = self.get_text_value("材质FAB2")
  295. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 100)
  296. font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60)
  297. font3 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  298. titleBg = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  299. titleBg = titleBg.get_text_image_advanced(
  300. value=(0, 0),
  301. font=font,
  302. text=textTitle1,
  303. align="left",
  304. spacing=5,
  305. fill=(53, 49, 48),
  306. return_mode="min_image",
  307. )
  308. top_bg.paste_img(top_img=titleBg, value=(0, 100),base='nc')
  309. text_bg2 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  310. text_bg2 = titleBg.get_text_image_advanced(
  311. value=(0, 0),
  312. font=font2,
  313. text=textTitle2,
  314. align="left",
  315. spacing=5,
  316. fill=(53, 49, 48),
  317. return_mode="min_image",
  318. )
  319. top_bg.paste_img(top_img=text_bg2, value=(0, 230),base='nc')
  320. textTitle3 = self.get_text_value("材质FAB3")
  321. text_bg3 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  322. text_bg3 = text_bg3.get_text_image_advanced(
  323. value=(0, 0),
  324. font=font3,
  325. text=textTitle3,
  326. align="center",
  327. spacing=5,
  328. fill=(53, 49, 48),
  329. return_mode="min_image",
  330. max_len_one_line=4
  331. )
  332. top_bg.paste_img(top_img=text_bg3, value=(154, 1325),base='nw')
  333. textTitle4 = self.get_text_value("材质FAB4")
  334. text_bg4 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  335. text_bg4 = text_bg4.get_text_image_advanced(
  336. value=(0, 0),
  337. font=font3,
  338. text=textTitle4,
  339. align="center",
  340. spacing=5,
  341. fill=(53, 49, 48),
  342. return_mode="min_image",
  343. max_len_one_line=4
  344. )
  345. top_bg.paste_img(top_img=text_bg4, value=(0, 1325),base='nc')
  346. textTitle5 = self.get_text_value("材质FAB5")
  347. text_bg5 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  348. text_bg5 = text_bg5.get_text_image_advanced(
  349. value=(0, 0),
  350. font=font3,
  351. text=textTitle5,
  352. align="center",
  353. spacing=5,
  354. fill=(53, 49, 48),
  355. return_mode="min_image",
  356. max_len_one_line=4
  357. )
  358. top_bg.paste_img(top_img=text_bg5, value=(154, 1325),base='en')
  359. detail_images.append(top_bg)
  360. return PictureProcessing(im=self.add_pic(detail_images))
  361. def deal_pic_5(self):
  362. detailed_images = []
  363. goods_art_no_list = list(self.data.keys())
  364. top_bg = PictureProcessing(
  365. r"{}\template_6.jpg".format(
  366. self.root
  367. )
  368. )
  369. detailed_images.append(top_bg)
  370. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  371. def deal_pic_6(self):
  372. detailed_images = []
  373. goods_art_no_list = list(self.data.keys())
  374. top_bg = PictureProcessing(
  375. r"{}\template_7.jpg".format(
  376. self.root
  377. )
  378. )
  379. detailed_images.append(top_bg)
  380. shoesBg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
  381. pp_jpg = self.get_overlay_pic_from_dict(
  382. goods_art_no=goods_art_no_list[0],
  383. color_name="俯视",
  384. bg_color=self.white_bg_color,
  385. )
  386. _, pp_png = self.image_one_pic(return_orign=True,
  387. goods_art_no=goods_art_no_list[0],
  388. name="俯视",
  389. )
  390. pp_png = pp_png.resize(value=(600))
  391. pp_jpg = pp_jpg.resize(value=(600))
  392. hengxian = PictureProcessing(
  393. r"{}\hengxian.png".format(
  394. self.root
  395. )
  396. )
  397. shuxian = PictureProcessing(
  398. r"{}\shuxian.png".format(
  399. self.root
  400. )
  401. )
  402. bbox = pp_png.get_im().getbbox()
  403. cropped_img = pp_png.get_im().crop(bbox)
  404. hengxian = hengxian.resize(value=(cropped_img.width))
  405. shuxian = shuxian.resize(value=(cropped_img.height),base='high')
  406. shoesBg.paste_img(top_img=pp_jpg, value=(0, 0),base='cc')
  407. shoesBg.paste_img(top_img=hengxian, value=(0, 80),base='cs')
  408. shoesBg.paste_img(top_img=shuxian, value=((shoesBg.width/2- pp_png.width/2), 0),base='ec')
  409. xiechang = self.get_text_value("鞋长")
  410. banggao = self.get_text_value("帮高")
  411. gen_gao = self.get_text_value("跟高")
  412. xiezhang_kuan = self.get_text_value("鞋掌宽")
  413. size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30)
  414. xiechang_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  415. xiechang_bg = xiechang_bg.get_text_image_advanced(
  416. value=(0, 0),
  417. font=size_font,
  418. text=xiechang,
  419. align="center",
  420. fill=self.black_bg_color,
  421. spacing=5,
  422. return_mode="min_image",
  423. )
  424. shoesBg.paste_img(top_img=xiechang_bg, value=(0, 50),base='cs')
  425. banggao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  426. banggao_bg = banggao_bg.get_text_image_advanced(
  427. value=(0, 0),
  428. font=size_font,
  429. text=banggao,
  430. align="center",
  431. fill=self.black_bg_color,
  432. spacing=5,
  433. return_mode="min_image",
  434. )
  435. shoesBg.paste_img(top_img=banggao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='en')
  436. gen_gao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  437. gen_gao_bg = gen_gao_bg.get_text_image_advanced(
  438. value=(0, 0),
  439. font=size_font,
  440. text=gen_gao,
  441. align="center",
  442. fill=self.black_bg_color,
  443. spacing=5,
  444. return_mode="min_image",
  445. )
  446. shoesBg.paste_img(top_img=gen_gao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='es')
  447. xiezhang_kuan_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  448. xiezhang_kuan_bg = xiezhang_kuan_bg.get_text_image_advanced(
  449. value=(0, 0),
  450. font=size_font,
  451. text=xiezhang_kuan,
  452. align="center",
  453. fill=self.black_bg_color,
  454. spacing=5,
  455. return_mode="min_image",
  456. )
  457. shoesBg.paste_img(top_img=xiezhang_kuan_bg,value=((shoesBg.width/2- pp_png.width/2), int(shoesBg.height*0.33)),base='nw')
  458. detailed_images.append(shoesBg)
  459. text_bg5 = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  460. detailed_images.append(text_bg5)
  461. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  462. def deal_pic_7(self):
  463. detailed_images = []
  464. top_bg = PictureProcessing(r"{}\template_6.jpg".format(self.root))
  465. attiribute = PictureProcessing("RGB", (top_bg.width, 300), (255, 255, 255))
  466. x_position = top_bg.width*0.15
  467. text_array = [
  468. {"text":"品牌","position":(x_position,50),"default":"小苏",'base':'nw'},
  469. {"text":"货号","position":(x_position,50),"default":"未填写",'base':'en'},
  470. {"text":"鞋面","position":(x_position,120),"default":"未填写",'base':'nw'},
  471. {"text":"内里","position":(x_position,120),"default":"未填写",'base':'en'},
  472. {"text":"鞋垫","position":(x_position,190),"default":"未填写",'base':'nw'},
  473. {"text":"鞋底","position":(x_position,190),"default":"未填写",'base':'en'},
  474. ]
  475. size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 40)
  476. for item in text_array:
  477. text_flag = item["text"]
  478. position = item["position"]
  479. default = item["default"]
  480. base = item["base"]
  481. text_value = self.get_text_value(item["text"])
  482. if not text_value:
  483. text_value = default
  484. gen_gao_bg = PictureProcessing("RGBA", (top_bg.width, 500), (255, 255, 255,0))
  485. gen_gao_bg = gen_gao_bg.get_text_image_advanced(
  486. value=(0, 0),
  487. font=size_font,
  488. text=f"【{text_flag}】:{text_value}",
  489. align="center",
  490. fill=self.black_bg_color,
  491. spacing=5,
  492. return_mode="min_image",
  493. )
  494. attiribute.paste_img(top_img=gen_gao_bg, value=position,base=base)
  495. bottom = PictureProcessing(r"{}\bottom.jpg".format(self.root))
  496. detailed_images.append(attiribute)
  497. detailed_images.append(bottom)
  498. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  499. def deal_pic_8(self):
  500. detailed_images = []
  501. top_bg = PictureProcessing(r"{}\template_10.jpg".format(self.root))
  502. detailed_images.append(top_bg)
  503. bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  504. detailed_images.append(bg_bottom)
  505. # ==========添加颜色===================
  506. pp_list_1 = []
  507. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 25)
  508. goods_art_no_list = list(self.data.keys())
  509. all_color_name = []
  510. for index, goods_art_no in enumerate(goods_art_no_list):
  511. pp_jpg = self.get_overlay_pic_from_dict(
  512. goods_art_no=goods_art_no,
  513. color_name="俯视",
  514. bg_color=self.white_bg_color,
  515. )
  516. if pp_jpg is None:
  517. continue
  518. pp_jpg = pp_jpg.resize(value=440)
  519. color_name = self.goods_no_value["货号资料"][index]["颜色名称"]
  520. all_color_name.append(color_name)
  521. text_bg = PictureProcessing("RGB", (440, 200), self.white_bg_color)
  522. text_bg = text_bg.get_text_image_advanced(
  523. value=(220, 10),
  524. font=font,
  525. text="{}".format(color_name),
  526. align="center",
  527. anchor="mm",
  528. spacing=5,
  529. fill=(55, 55, 55),
  530. return_mode="min_image_high",
  531. margins=(10, 5, 0, 0)
  532. )
  533. # text_bg.show()
  534. _bg = PictureProcessing("RGB", (440, pp_jpg.height + text_bg.height), self.white_bg_color)
  535. _bg = _bg.paste_img(top_img=pp_jpg)
  536. _bg = _bg.paste_img(top_img=text_bg, value=(0, pp_jpg.height))
  537. pp_list_1.append(_bg)
  538. rows = 2
  539. shoes_bg = PictureProcessing().horizontal_distribution(
  540. pp_list=pp_list_1,
  541. bg_width=1200,
  542. margins=(0, 0, 40, 40),
  543. line_spacing=60,
  544. number_per_row=rows,
  545. )
  546. detailed_images.append(shoes_bg)
  547. bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  548. detailed_images.append(bg_bottom)
  549. return PictureProcessing(im=self.add_pic(detailed_images))
  550. def deal_pic_9(self):
  551. detailed_images = []
  552. goods_art_no_list = list(self.data.keys())
  553. top_bg = PictureProcessing(r"{}\template_12.jpg".format(self.root))
  554. detailed_images.append(top_bg)
  555. # 鞋头
  556. _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
  557. radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
  558. radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
  559. _, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name="内里")
  560. pp_png = pp_png.resize(value=round(top_bg.width*1.5))
  561. pp_png = pp_png.rotate(doge=-120)
  562. # _bg = _bg.paste_img(top_img=pp_png, value=(0, 0),base='cc')
  563. radius_react.paste_img(top_img=pp_png, value=(0, 0),base='cc')
  564. detailed_images.append(radius_react)
  565. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  566. detailed_images.append(line)
  567. # 鞋跟
  568. _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
  569. radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
  570. radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
  571. _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
  572. detailed_images.append(_bg)
  573. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  574. detailed_images.append(line)
  575. # 鞋底
  576. _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
  577. radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
  578. radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
  579. _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
  580. pp_jpg, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name="俯视")
  581. pp_jpg = pp_jpg.resize(value=round(top_bg.width*0.8))
  582. pp_png = pp_png.resize(value=round(top_bg.width*0.8))
  583. top_bg = top_bg.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc",value=(0, 0))
  584. detailed_images.append(_bg)
  585. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  586. detailed_images.append(line)
  587. # 鞋底
  588. return PictureProcessing(im=self.add_pic(detailed_images))
  589. def deal_pic_10(self):
  590. # template_15.jpg
  591. # 模特展示
  592. top_bg = PictureProcessing(r"{}\template_15.jpg".format(self.root))
  593. detailed_images = []
  594. detailed_images.append(top_bg)
  595. return PictureProcessing(im=self.add_pic(detailed_images))
  596. def deal_pic_11(self):
  597. detailed_images = []
  598. detailed_images.append(PictureProcessing(r"{}\template_22.jpg".format(self.root)))
  599. return PictureProcessing(im=self.add_pic(detailed_images))
  600. def get_font_render_size(self, text, font, canvas_size=(2048, 2048)):
  601. canvas = Image.new('RGB', canvas_size)
  602. draw = ImageDraw.Draw(canvas)
  603. draw.text((0, 0), text, font=font, fill=(55, 55, 55))
  604. bbox = canvas.getbbox()
  605. # 宽高
  606. size = (bbox[2] - bbox[0], bbox[3] - bbox[1])
  607. return size