detail_xiaosushuoxie2.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. from PIL import ImageFont, Image, ImageDraw
  9. from module.view_control.generate_goods_no_detail_pic.detail_generate_base import (
  10. DetailBase,
  11. )
  12. from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  13. import math
  14. class DetailPicGetXiaoSuShuoXie2(DetailBase):
  15. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  16. root = r"{}\resources\detail_temp\xiaosushuoxie\2".format(os.getcwd())
  17. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False, excel_data=None,assigned_page_list=None):
  18. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows, excel_data=excel_data,assigned_page_list=assigned_page_list)
  19. self.root = r"{}\resources\detail_temp\xiaosushuoxie\2".format(os.getcwd())
  20. self.base_bg_color = (235, 234, 234)
  21. self.deal_pic_func_list = [
  22. self.deal_pic_1,
  23. self.deal_pic_2,
  24. self.deal_pic_3,
  25. self.deal_pic_4,
  26. self.deal_pic_5,
  27. self.deal_pic_6,
  28. self.deal_pic_7,
  29. ]
  30. if test:
  31. self.run_test()
  32. else:
  33. self.run_all()
  34. def run_test(self):
  35. detailed_images = []
  36. detailed_images.append(self.deal_pic_1())
  37. detailed_images.append(self.deal_pic_2())
  38. detailed_images.append(self.deal_pic_3())
  39. detailed_images.append(self.deal_pic_4())
  40. detailed_images.append(self.deal_pic_5())
  41. detailed_images.append(self.deal_pic_6())
  42. detailed_images.append(self.deal_pic_7())
  43. img = self.add_pic(detailed_images)
  44. img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  45. def deal_pic_1(self):
  46. """ 制作主图 """
  47. detailed_images = []
  48. # -------粘贴文字-------
  49. pp_bg = PictureProcessing(r"{}\template_1.png".format(self.root))
  50. detailed_images.append(pp_bg)
  51. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
  52. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 35)
  53. # font_2 = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 35)
  54. t1_title = self.get_text_value("标题")
  55. t1_sub_title = self.get_text_value("副标题")
  56. # t1_sub_title = "副标题副标题副标题副标题副标题\n副标题副标题副标题副标题\n副标题副标题副标题"
  57. base_bg_color = (236, 235, 235)
  58. if t1_title:
  59. t_title_pp = PictureProcessing("RGB", (1200, 500), base_bg_color)
  60. t_title_pp = t_title_pp.get_text_image_advanced(
  61. value=(50, 10),
  62. font=font_1,
  63. text=t1_title,
  64. align="left",
  65. spacing=10,
  66. fill=(17, 16, 16),
  67. return_mode="min_image_high",
  68. margins=(0, 0, 0, 0)
  69. )
  70. detailed_images.append(t_title_pp)
  71. if t1_sub_title:
  72. t_title_2_pp = PictureProcessing("RGB", (1200, 500), base_bg_color)
  73. t_title_2_pp = t_title_2_pp.get_text_image_advanced(
  74. value=(50, 10),
  75. font=font_2,
  76. text=t1_sub_title,
  77. align="left",
  78. spacing=10,
  79. fill=(32, 32, 32),
  80. return_mode="min_image_high",
  81. margins=(0, 0, 0, 0)
  82. )
  83. detailed_images.append(t_title_2_pp)
  84. # 添加分割线
  85. detailed_images.append(PictureProcessing("RGB",(pp_bg.width,150),self.base_bg_color))
  86. # ================添加图片
  87. goods_art_no_list = list(self.data.keys())
  88. _zuhe_pic_list = []
  89. color_name_list = ["组合", "组合2", "组合3"]
  90. for color_name in color_name_list:
  91. pp_1 = self.get_overlay_pic_from_dict(
  92. goods_art_no=goods_art_no_list[0],
  93. color_name=color_name,
  94. bg_color=self.base_bg_color,
  95. )
  96. if not pp_1:
  97. continue
  98. pp_1 = pp_1.resize(value=int(pp_bg.width / 1.45))
  99. pp_1 = pp_1.paste_img_invert(
  100. top_img=PictureProcessing("RGB", (pp_bg.width, pp_1.height + 30), self.base_bg_color),
  101. base="cc")
  102. _zuhe_pic_list.append(pp_1)
  103. if not _zuhe_pic_list:
  104. pp_1 = self.get_overlay_pic_from_dict(
  105. goods_art_no=goods_art_no_list[0],
  106. color_name="俯视",
  107. bg_color=self.base_bg_color,
  108. )
  109. pp_1 = pp_1.resize(value=int(pp_bg.width / 1.45))
  110. pp_1 = pp_1.paste_img_invert(
  111. top_img=PictureProcessing("RGB", (pp_bg.width, pp_1.height + 30), self.base_bg_color),
  112. base="cc")
  113. _zuhe_pic_list.append(pp_1)
  114. detailed_images.extend(_zuhe_pic_list)
  115. # 添加分割线
  116. detailed_images.append(PictureProcessing("RGB",(pp_bg.width,150),self.base_bg_color))
  117. return PictureProcessing(im=self.add_pic(detailed_images))
  118. def deal_pic_2(self):
  119. """
  120. 细节解析
  121. """
  122. detailed_images = []
  123. pp_bg = PictureProcessing(r"{}\template_2.png".format(self.root))
  124. detailed_images.append(pp_bg)
  125. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
  126. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 30)
  127. t1_title = self.get_text_value("提示1主标题")
  128. t1_sub_title = self.get_text_value("提示1副标题")
  129. if t1_title:
  130. t_title_pp = PictureProcessing("RGB", (1200, 500), (249, 249, 249))
  131. t_title_pp = t_title_pp.get_text_image_advanced(
  132. value=(1200 - 80, 45),
  133. font=font_1,
  134. text=t1_title,
  135. align="right",
  136. anchor="rs",
  137. spacing=10,
  138. fill=(17, 16, 16),
  139. return_mode="min_image_high",
  140. margins=(10, 10, 0, 0)
  141. )
  142. detailed_images.append(t_title_pp)
  143. if t1_sub_title:
  144. t_title_2_pp = PictureProcessing("RGB", (1200, 500), (249, 249, 249))
  145. t_title_2_pp = t_title_2_pp.get_text_image_advanced(
  146. value=(1200 - 80, 30),
  147. font=font_2,
  148. text=t1_sub_title,
  149. align="right",
  150. anchor="rs",
  151. spacing=10,
  152. fill=(55, 55, 55),
  153. return_mode="min_image_high",
  154. margins=(10, 10, 0, 0)
  155. )
  156. detailed_images.append(t_title_2_pp)
  157. # ----------主图放置
  158. goods_art_no_list = list(self.data.keys())
  159. # ---------------鞋底图
  160. bg_color = (249, 249, 249)
  161. pp_jpg = self.get_overlay_pic_from_dict(
  162. goods_art_no=goods_art_no_list[0],
  163. color_name="鞋底",
  164. bg_color=bg_color
  165. )
  166. pp_jpg = pp_jpg.paste_img_invert(top_img=PictureProcessing("RGB", (1200, pp_jpg.height + 100), bg_color),
  167. base="nc",
  168. value=(400, 00)
  169. )
  170. detailed_images.append(pp_jpg)
  171. return PictureProcessing(im=self.add_pic(detailed_images))
  172. def deal_pic_3(self):
  173. detailed_images = []
  174. pp_bg = PictureProcessing(r"{}\template_4.png".format(self.root))
  175. detailed_images.append(pp_bg)
  176. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
  177. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 30)
  178. t1_title = self.get_text_value("提示2主标题")
  179. t1_sub_title = self.get_text_value("提示2副标题")
  180. bg_color = (252, 252, 252)
  181. if t1_title:
  182. t_title_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  183. t_title_pp = t_title_pp.get_text_image_advanced(
  184. value=(80, 45),
  185. font=font_1,
  186. text=t1_title,
  187. align="left",
  188. anchor=None,
  189. spacing=10,
  190. fill=(17, 16, 16),
  191. return_mode="min_image_high",
  192. margins=(10, 10, 0, 0)
  193. )
  194. detailed_images.append(t_title_pp)
  195. if t1_sub_title:
  196. t_title_2_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  197. t_title_2_pp = t_title_2_pp.get_text_image_advanced(
  198. value=(80, 30),
  199. font=font_2,
  200. text=t1_sub_title,
  201. align="left",
  202. anchor=None,
  203. spacing=10,
  204. fill=(55, 55, 55),
  205. return_mode="min_image_high",
  206. margins=(10, 10, 0, 0)
  207. )
  208. detailed_images.append(t_title_2_pp)
  209. # ----------主图放置
  210. goods_art_no_list = list(self.data.keys())
  211. # ---------------鞋底图
  212. pp_jpg = self.get_overlay_pic_from_dict(
  213. goods_art_no=goods_art_no_list[0],
  214. color_name="侧视",
  215. bg_color=bg_color
  216. )
  217. pp_jpg = pp_jpg.resize(value=1686)
  218. pp_jpg = pp_jpg.paste_img_invert(top_img=PictureProcessing("RGB", (1200, pp_jpg.height), bg_color),
  219. base="ec",
  220. value=(0, 0)
  221. )
  222. # pp_jpg = pp_jpg.resize(value=1000)
  223. # pp_jpg = pp_jpg.paste_img_invert(top_img=PictureProcessing("RGB",(1200,pp_jpg.height+150),bg_color),
  224. # base="wc",
  225. # value=(0,0)
  226. # )
  227. detailed_images.append(pp_jpg)
  228. return PictureProcessing(im=self.add_pic(detailed_images))
  229. def deal_pic_4(self):
  230. """各个颜色细节展示"""
  231. bg_color = (235, 235, 235)
  232. detailed_images = []
  233. pp_bg = PictureProcessing(r"{}\template_5.png".format(self.root))
  234. detailed_images.append(pp_bg)
  235. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
  236. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 30)
  237. t1_title = self.get_text_value("提示3主标题")
  238. t1_sub_title = self.get_text_value("提示3副标题")
  239. if t1_title:
  240. t_title_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  241. t_title_pp = t_title_pp.get_text_image_advanced(
  242. value=(1200 - 80, 45),
  243. font=font_1,
  244. text=t1_title,
  245. align="right",
  246. anchor="rs",
  247. spacing=10,
  248. fill=(17, 16, 16),
  249. return_mode="min_image_high",
  250. margins=(10, 10, 0, 0)
  251. )
  252. detailed_images.append(t_title_pp)
  253. if t1_sub_title:
  254. t_title_2_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  255. t_title_2_pp = t_title_2_pp.get_text_image_advanced(
  256. value=(1200 - 80, 30),
  257. font=font_2,
  258. text=t1_sub_title,
  259. align="right",
  260. anchor="rs",
  261. spacing=10,
  262. fill=(55, 55, 55),
  263. return_mode="min_image_high",
  264. margins=(10, 10, 0, 0)
  265. )
  266. detailed_images.append(t_title_2_pp)
  267. goods_art_no_list = list(self.data.keys())
  268. # ------侧视图-------------
  269. pp_2 = self.image_one_pic(
  270. goods_art_no=goods_art_no_list[0], name="侧视", bg_color=bg_color
  271. )
  272. pp_2 = pp_2.resize(mode="pixel", base="width", value=2327)
  273. pp_2 = PictureProcessing("RGBA", (200, 300), bg_color).paste_img(
  274. mode="pixel", top_img=pp_2, base="wc", value=(-900, 0)
  275. )
  276. # ------侧视-------------
  277. pp_3 = self.image_one_pic(
  278. goods_art_no=goods_art_no_list[0], name="侧视", bg_color=bg_color
  279. )
  280. pp_3 = pp_3.resize(mode="pixel", base="width", value=3000)
  281. pp_3 = PictureProcessing("RGBA", (200, 300), bg_color).paste_img(
  282. mode="pixel", top_img=pp_3, base="cc", value=(-500, 0)
  283. )
  284. # ---------------侧视图---------------旋转
  285. _, pp_4 = self.image_one_pic(
  286. goods_art_no=goods_art_no_list[0],
  287. name="侧视",
  288. bg_color=bg_color,
  289. return_orign=True,
  290. )
  291. pp_4 = pp_4.resize(mode="pixel", base="width", value=1163)
  292. pp_4_max = pp_4.width if pp_4.width > pp_4.height else pp_4.height
  293. past_y = 0
  294. top_img_bg = PictureProcessing("RGBA", (pp_bg.width, pp_2.height), bg_color)
  295. top_img_bg = top_img_bg.paste_img(
  296. mode="pixel", top_img=pp_2, base="wc", value=(50, past_y)
  297. )
  298. top_img_bg = top_img_bg.paste_img(
  299. mode="pixel", top_img=pp_3, base="wc", value=(267, past_y)
  300. )
  301. new_pp4_bg = PictureProcessing(
  302. "RGBA", (pp_4_max, pp_4_max + 100), (239, 239, 239, 0)
  303. )
  304. pp_4 = PictureProcessing("RGBA", (pp_4.width, pp_4.height), bg_color).paste_img(
  305. mode="pixel", top_img=pp_4, base="nw", value=(0, 0)
  306. )
  307. new_pp4_bg.paste_img(mode="pixel", top_img=pp_4, base="wc", value=(0, 0))
  308. new_pp4_bg = new_pp4_bg.rotate(30)
  309. pp4_im = new_pp4_bg.get_im()
  310. new_pp4_im = pp4_im.crop(pp4_im.getbbox())
  311. new_pp5_bg = PictureProcessing(
  312. "RGBA", (pp_bg.width, new_pp4_im.height - 200), bg_color
  313. )
  314. new_pp5_bg = new_pp5_bg.paste_img(
  315. mode="pixel", top_img=new_pp4_bg, base="cc", value=(-50, 0)
  316. )
  317. new_empty_bg = PictureProcessing("RGBA", (pp_bg.width, 50), bg_color)
  318. detailed_images.append(top_img_bg)
  319. detailed_images.append(new_pp5_bg)
  320. detailed_images.append(new_empty_bg)
  321. return PictureProcessing(im=self.add_pic(detailed_images))
  322. def deal_pic_5(self):
  323. bg_color = (255, 255, 255)
  324. detailed_images = []
  325. # =============文字=================
  326. font_1 = ImageFont.truetype(r"resources\ttf\puhui\en\Black.otf", 65)
  327. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 65)
  328. t1_title = "INFORMATION"
  329. t1_sub_title = "产品信息"
  330. if t1_title:
  331. t_title_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  332. t_title_pp = t_title_pp.get_text_image_advanced(
  333. value=(600, 45),
  334. font=font_1,
  335. text=t1_title,
  336. align="center",
  337. anchor="mm",
  338. spacing=10,
  339. fill=(16, 16, 16),
  340. return_mode="min_image_high",
  341. margins=(10, 10, 0, 0)
  342. )
  343. detailed_images.append(t_title_pp)
  344. if t1_sub_title:
  345. t_title_2_pp = PictureProcessing("RGB", (1200, 500), bg_color)
  346. t_title_2_pp = t_title_2_pp.get_text_image_advanced(
  347. value=(600, 30),
  348. font=font_2,
  349. text=t1_sub_title,
  350. align="center",
  351. anchor="mm",
  352. spacing=10,
  353. fill=(16, 16, 16),
  354. return_mode="min_image_high",
  355. margins=(10, 10, 0, 0)
  356. )
  357. detailed_images.append(t_title_2_pp)
  358. goods_art_no_list = list(self.data.keys())
  359. product_img = self.get_overlay_pic_from_dict(
  360. goods_art_no=goods_art_no_list[0],
  361. color_name="俯视",
  362. bg_color=bg_color
  363. )
  364. product_img = product_img.resize(value=1200 / 1.75)
  365. product_img = product_img.paste_img_invert(
  366. top_img=PictureProcessing("RGB", (1200, product_img.height), bg_color),
  367. base="cc",
  368. )
  369. text_font = ImageFont.truetype(r"resources\ttf\puhui\Regular.otf", 30)
  370. tips_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30)
  371. h = 280 if product_img.height < 312 else 312
  372. paramsList = [("帮高", (140, product_img.height - h)), ("跟高", (1200 - 140, product_img.height - h)),
  373. ("鞋宽", (1200 - 140, product_img.height - 87))]
  374. tipsList = [("帮高", (140, product_img.height - h - 30)), ("跟高", (1200 - 140, product_img.height - h - 30)),
  375. ("鞋宽", (1200 - 140, product_img.height - 87 - 30))]
  376. for index,item in enumerate(paramsList):
  377. text ="{}".format(self.get_text_value(item[0]))
  378. if not text:
  379. continue
  380. product_img = product_img.add_text(
  381. mode="pixel",
  382. value=item[1],
  383. font=text_font,
  384. anchor="mm",
  385. text=text,
  386. align="center",
  387. spacing=10,
  388. fill=(143, 143, 143),
  389. )
  390. product_img = product_img.add_text(
  391. mode="pixel",
  392. value=tipsList[index][1],
  393. font=tips_font,
  394. anchor="mm",
  395. text="{}".format(tipsList[index][0]),
  396. align="center",
  397. spacing=15,
  398. fill=(143, 143, 143),
  399. )
  400. detailed_images.append(product_img)
  401. # ===========================================================================================================d
  402. pp_bg = PictureProcessing(r"{}\template_6.png".format(self.root))
  403. tableList = [
  404. ("鞋面材质", (300, 72)),
  405. ("内里材质", (760, 72)),
  406. ("鞋垫材质", (300, 72 + 105)),
  407. ("鞋底材质", (760, 72 + 105)),
  408. ]
  409. table_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30)
  410. spacing = 15
  411. text_arrays = []
  412. for i, tableItem in enumerate(tableList):
  413. item_text = self.get_text_value(tableItem[0])
  414. if not item_text:
  415. continue
  416. text_arrays.append("{} : {}".format(tableItem[0], item_text))
  417. for index, item in enumerate(text_arrays):
  418. row = index // 2 + 1 # 计算行号(从1开始计数)
  419. col = (index % 2) + 1 # 计算列号(从1开始计数)
  420. if col == 1:
  421. c_x = 102
  422. else:
  423. c_x = 635
  424. if row == 1:
  425. c_y = 40
  426. else:
  427. c_y = 40 + 105
  428. pp_bg = pp_bg.add_text(
  429. mode="pixel",
  430. value=(c_x, c_y),
  431. font=table_font,
  432. text=item,
  433. align="left",
  434. spacing=spacing,
  435. fill=(80, 80, 80),
  436. )
  437. detailed_images.append(pp_bg)
  438. return PictureProcessing(im=self.add_pic(detailed_images))
  439. def searchNotEmptyItem(self, current_idx, tableList):
  440. idx = current_idx - 1
  441. if idx < 0:
  442. idx = 0
  443. value = self.get_text_value(tableList[idx][0])
  444. if idx == 0:
  445. return idx
  446. if value == "":
  447. return self.searchNotEmptyItem(idx, tableList)
  448. else:
  449. return idx + 1
  450. def deal_pic_6(self):
  451. bg_color = (255, 255, 255)
  452. detailed_images = []
  453. pp_bg = PictureProcessing(r"{}\template_7.png".format(self.root))
  454. detailed_images.append(pp_bg)
  455. # ==========添加颜色===================
  456. pp_list_1 = []
  457. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 25)
  458. goods_art_no_list = list(self.data.keys())
  459. all_color_name = []
  460. for index, goods_art_no in enumerate(goods_art_no_list):
  461. pp_jpg = self.get_overlay_pic_from_dict(
  462. goods_art_no=goods_art_no,
  463. color_name="侧视",
  464. bg_color=bg_color,
  465. )
  466. if pp_jpg is None:
  467. continue
  468. pp_jpg = pp_jpg.resize(value=440)
  469. color_name = self.goods_no_value["货号资料"][index]["颜色名称"]
  470. all_color_name.append(color_name)
  471. text_bg = PictureProcessing("RGB", (440, 200), bg_color)
  472. text_bg = text_bg.get_text_image_advanced(
  473. value=(220, 10),
  474. font=font,
  475. text="{}".format(color_name),
  476. align="center",
  477. anchor="mm",
  478. spacing=5,
  479. fill=(55, 55, 55),
  480. return_mode="min_image_high",
  481. margins=(10, 5, 0, 0)
  482. )
  483. # text_bg.show()
  484. _bg = PictureProcessing("RGB", (440, pp_jpg.height + text_bg.height), bg_color)
  485. _bg = _bg.paste_img(top_img=pp_jpg)
  486. _bg = _bg.paste_img(top_img=text_bg, value=(0, pp_jpg.height))
  487. pp_list_1.append(_bg)
  488. rows = 2
  489. shoes_bg = PictureProcessing().horizontal_distribution(
  490. pp_list=pp_list_1,
  491. bg_width=1200,
  492. margins=(0, 0, 40, 40),
  493. line_spacing=60,
  494. number_per_row=rows,
  495. )
  496. detailed_images.append(shoes_bg)
  497. return PictureProcessing(im=self.add_pic(detailed_images))
  498. def get_font_render_size(self, text, font):
  499. canvas = Image.new("RGB", (2048, 2048))
  500. draw = ImageDraw.Draw(canvas)
  501. draw.text((0, 0), text, font=font, fill=(55, 55, 55))
  502. bbox = canvas.getbbox()
  503. # 宽高
  504. size = (bbox[2] - bbox[0], bbox[3] - bbox[1])
  505. return size
  506. def deal_pic_7(self):
  507. detailed_images = []
  508. bg_color = (255, 255, 255)
  509. goods_art_no_list = list(self.data.keys())
  510. pp_bg = PictureProcessing(r"{}\template_8.png".format(self.root))
  511. detailed_images.append(pp_bg)
  512. color_name_1 = ["俯视", "侧视", "内里", "后跟", "鞋底"]
  513. color_name_2 = ["俯视", "鞋底"]
  514. color_name_1 = ["俯视", "侧视", "鞋底"]
  515. color_name_2 = ["俯视", "内里", "后跟"]
  516. for index, goods_art_no in enumerate(goods_art_no_list):
  517. if index in [0, 2, 4, 6, 8]:
  518. color_name = color_name_1
  519. else:
  520. color_name = color_name_2
  521. for name in color_name:
  522. pp_jpg = self.get_overlay_pic_from_dict(
  523. goods_art_no=goods_art_no,
  524. color_name=name,
  525. bg_color=bg_color
  526. )
  527. if pp_jpg:
  528. if name != "后跟":
  529. pp_jpg = pp_jpg.resize(value=int(pp_bg.width / 1.2))
  530. else:
  531. pp_jpg = pp_jpg.resize(value=int(pp_bg.width / 2.2))
  532. pp_jpg = pp_jpg.paste_img_invert(
  533. top_img=PictureProcessing("RGB", (pp_bg.width, pp_jpg.height + 30), bg_color),
  534. base="cc")
  535. detailed_images.append(pp_jpg)
  536. detailed_images.append(PictureProcessing("RGB", (pp_bg.width, 220), bg_color))
  537. return PictureProcessing(im=self.add_pic(detailed_images))
  538. if __name__ == "__main__":
  539. import json
  540. with open(
  541. r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\auto_capture_V2\auto_photo\qt_test\data3.txt",
  542. "r",
  543. encoding="utf-8",
  544. ) as f:
  545. data = json.loads(f.read())
  546. for goods_no, value in data.items():
  547. d = DetailPicGetXiaoSuShuoXie2(
  548. goods_no,
  549. value,
  550. out_put_dir=r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\auto_capture_V2\auto_photo\output\2024-11-19\软件-详情图生成",
  551. )
  552. raise 1