detail_xiaosushuoxie2.py 24 KB

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