detail_xiaosushuoxie6.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. import time
  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. from PIL import Image, ImageDraw
  13. import math
  14. class DetailPicGetXiaoSuShuoXie6(DetailBase):
  15. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  16. root = r"{}\resources\detail_temp\xiaosushuoxie\6".format(os.getcwd())
  17. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False, excel_data=None,
  18. assigned_page_list=None):
  19. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows, excel_data=excel_data,
  20. assigned_page_list=assigned_page_list)
  21. self.root = r"{}\resources\detail_temp\xiaosushuoxie\6".format(os.getcwd())
  22. print("run xiaosushuoxie-6 ")
  23. self.base_bg_color = (228, 196, 147)
  24. self.deal_pic_func_list = [
  25. self.deal_pic_1,
  26. self.deal_pic_2,
  27. self.deal_pic_3,
  28. self.deal_pic_4,
  29. self.deal_pic_5,
  30. self.deal_pic_6,
  31. self.deal_pic_7,
  32. self.deal_pic_8,
  33. self.deal_pic_9,
  34. ]
  35. if test:
  36. # pp_1 = self.generate_font_list_to_pic()
  37. # pp_1.im.save(r"C:\Users\gymmc\Desktop\细节图示例/字号.png")
  38. # for k, v in self.goods_no_value.items():
  39. # print(k, v)
  40. self.run_test()
  41. else:
  42. self.run_all()
  43. def run_test(self):
  44. detailed_images = []
  45. # detailed_images.append(self.deal_pic_1())
  46. # detailed_images.append(self.deal_pic_2())
  47. # detailed_images.append(self.deal_pic_3())
  48. # detailed_images.append(self.deal_pic_4())
  49. detailed_images.append(self.deal_pic_5())
  50. # detailed_images.append(self.deal_pic_6())
  51. # detailed_images.append(self.deal_pic_7())
  52. # detailed_images.append(self.deal_pic_8())
  53. # detailed_images.append(self.deal_pic_9())
  54. img = self.add_pic(detailed_images)
  55. # img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
  56. img.show()
  57. def deal_details_beifen(self):
  58. detailed_images = []
  59. self.image_list_append(detailed_images, self.deal_pic_1())
  60. self.image_list_append(detailed_images, self.deal_pic_2())
  61. self.image_list_append(detailed_images, self.deal_pic_3())
  62. self.image_list_append(detailed_images, self.deal_pic_4())
  63. self.image_list_append(detailed_images, self.deal_pic_5())
  64. self.image_list_append(detailed_images, self.deal_pic_6())
  65. self.image_list_append(detailed_images, self.deal_pic_7())
  66. self.image_list_append(detailed_images, self.deal_pic_8())
  67. self.image_list_append(detailed_images, self.deal_pic_9())
  68. return [x for x in detailed_images if x]
  69. # 组合图1
  70. def deal_pic_1(self):
  71. pp_bg = PictureProcessing(r"{}\t (1).jpg".format(self.root))
  72. # -------粘贴文字-------
  73. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 32) # 设计理念
  74. text_list = []
  75. text_list.append({"text": self.get_text_value("设计理念"),
  76. "font": font_1,
  77. "fill": (102, 92, 92),
  78. })
  79. text_image = self.add_text_list(text_list, spacing=15, base="nw")
  80. if text_image:
  81. pp_bg = pp_bg.paste_img(
  82. top_img=text_image,
  83. base="nw",
  84. value=(20, 895))
  85. # ----粘贴组合图
  86. goods_art_no_list = list(self.data.keys())
  87. goods_art_no = goods_art_no_list[0]
  88. view_list = ["组合", "俯视"]
  89. for view_name in view_list:
  90. pp_jpg_1, pp_png_1 = self.image_one_pic(return_orign=True,
  91. goods_art_no=goods_art_no,
  92. name=view_name,
  93. )
  94. if not pp_jpg_1:
  95. continue
  96. pp_jpg_1: PictureProcessing
  97. pp_png_1: PictureProcessing
  98. pp_jpg_1 = pp_jpg_1.resize(base_by_box=(485, 588))
  99. pp_png_1 = pp_png_1.resize(base_by_box=(485, 588))
  100. pp_bg = pp_bg.to_overlay_pic_advance(top_img=pp_jpg_1, top_png_img=pp_png_1,
  101. value=(947 - pp_jpg_1.width / 2, 888 - pp_jpg_1.height / 2), base="nw")
  102. break
  103. return pp_bg
  104. # 展示设计理念2和组合2
  105. def deal_pic_2(self):
  106. pp_bg = PictureProcessing(r"{}\t (2).jpg".format(self.root))
  107. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 32) # 设计理念
  108. text_list = []
  109. text_list.append({"text": self.get_text_value("设计理念2"),
  110. "font": font_1,
  111. "fill": (109, 103, 97),
  112. })
  113. text_image = self.add_text_list(text_list, spacing=15, base="nw")
  114. if text_image:
  115. pp_bg = pp_bg.paste_img(
  116. top_img=text_image,
  117. base="nw",
  118. value=(60, 141))
  119. # ====粘贴组合2或侧视图
  120. goods_art_no_list = list(self.data.keys())
  121. pp_jpg_1, pp_png_1 = self.image_one_pic(return_orign=True,
  122. goods_art_no=goods_art_no_list[0],
  123. name="组合2",
  124. )
  125. if not pp_jpg_1:
  126. pp_jpg_1, pp_png_1 = self.image_one_pic(return_orign=True,
  127. goods_art_no=goods_art_no_list[0],
  128. name="侧视",
  129. )
  130. pp_jpg_1: PictureProcessing
  131. pp_png_1: PictureProcessing
  132. pp_jpg_1 = pp_jpg_1.resize(base_by_box=(546, 592))
  133. pp_png_1 = pp_png_1.resize(base_by_box=(546, 592))
  134. pp_bg = pp_bg.to_overlay_pic_advance(top_img=pp_jpg_1, top_png_img=pp_png_1,
  135. value=(786 - pp_jpg_1.width / 2, 816 - pp_jpg_1.height / 2))
  136. return pp_bg
  137. # 亮点解析
  138. def deal_pic_3(self):
  139. detailed_images = []
  140. detailed_images.append(PictureProcessing(r"{}\t (3).jpg".format(self.root)))
  141. goods_art_no_list = list(self.data.keys())
  142. # =====添加内里图
  143. pp_bg_1 = PictureProcessing(r"{}\t (4).jpg".format(self.root))
  144. pp_jpg_1, pp_png_1 = self.image_one_pic(return_orign=True,
  145. goods_art_no=goods_art_no_list[0],
  146. name="内里",
  147. )
  148. pp_png_1: PictureProcessing
  149. pp_png_1 = pp_png_1.resize(value=1600)
  150. pp_png_1 = pp_png_1.paste_img_invert(top_img=PictureProcessing("RGB", (1200, 1061), (255, 255, 255)),
  151. base="ws",
  152. value=(-85, 0))
  153. # 添加内里描述
  154. _neili_bg = PictureProcessing(r"{}\t (25).png".format(self.root))
  155. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 38) # 内里描述
  156. text_list = [{"text": self.get_text_value("内里特点"),
  157. "font": font_1,
  158. "fill": (110, 110, 110),
  159. }]
  160. text_image = self.add_text_list(text_list, spacing=10, base="nc")
  161. if text_image:
  162. _neili_bg = _neili_bg.paste_img(
  163. top_img=text_image,
  164. base="sc",
  165. value=(0, 69))
  166. pp_bg_1 = pp_bg_1.paste_img(top_img=pp_png_1, base="sc", value=(0, 266))
  167. pp_bg_1 = pp_bg_1.paste_img(top_img=_neili_bg, base="sc", value=(0, 137))
  168. detailed_images.append(pp_bg_1)
  169. # ======添加鞋底图====
  170. pp_2 = self.get_overlay_pic_from_dict(goods_art_no=goods_art_no_list[0],
  171. color_name="鞋底",
  172. bg_color=(255, 255, 255),
  173. )
  174. pp_2 = pp_2.resize(value=1396)
  175. pp_bg_2 = PictureProcessing("RGB", (1200, pp_2.height + 80), (255, 255, 255))
  176. pp_bg_2 = pp_bg_2.paste_img(top_img=pp_2, base="wc", value=(80, 0))
  177. detailed_images.append(pp_bg_2)
  178. # --添加鞋底特点
  179. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 34) # 内里描述
  180. text_list = [{"text": self.get_text_value("鞋底特点"),
  181. "font": font_1,
  182. "fill": (110, 110, 110),
  183. }]
  184. text_image = self.add_text_list(text_list, spacing=10, base="nc")
  185. if text_image:
  186. pp_bg_3 = PictureProcessing("RGB", (1200, text_image.height + 80), (255, 255, 255))
  187. pp_bg_3 = pp_bg_3.paste_img(top_img=text_image, base="cc", value=(0, 0))
  188. detailed_images.append(pp_bg_3)
  189. # ---添加鞋子的俯视图,并标注尺寸----------------
  190. pp_bg_4 = PictureProcessing(r"{}\t (6).jpg".format(self.root))
  191. pp_4 = self.get_overlay_pic_from_dict(goods_art_no=goods_art_no_list[0],
  192. color_name="俯视",
  193. bg_color=(255, 255, 255),
  194. )
  195. pp_4 = pp_4.resize(value=332 * 1.8)
  196. pp_bg_4 = pp_bg_4.paste_img(top_img=pp_4, base="sc", value=(0, 222))
  197. # -添加文字描述等
  198. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 28)
  199. if self.get_text_value("鞋长"):
  200. text = "长:{}".format(self.get_text_value("鞋长"))
  201. text_image = pp_bg_4.get_text_image_advanced(font=font_1,
  202. text=text,
  203. fill=(110, 110, 110),
  204. return_mode="min_image")
  205. pp_bg_4 = pp_bg_4.paste_img(top_img=text_image, base="sc", value=(0, 134))
  206. if self.get_text_value("跟高"):
  207. text = "跟高:{}".format(self.get_text_value("跟高"))
  208. text_image = pp_bg_4.get_text_image_advanced(font=font_1,
  209. text=text,
  210. fill=(110, 110, 110),
  211. return_mode="min_image")
  212. pp_bg_4 = pp_bg_4.paste_img(top_img=text_image, base="se", value=(72, 404))
  213. if self.get_text_value("脚掌围"):
  214. text = "脚掌围:{}".format(self.get_text_value("脚掌围"))
  215. text_image = pp_bg_4.get_text_image_advanced(font=font_1,
  216. text=text,
  217. fill=(110, 110, 110),
  218. return_mode="min_image")
  219. pp_bg_4 = pp_bg_4.paste_img(top_img=text_image, base="sw", value=(179, 510))
  220. if pp_bg_4.height > pp_4.height + 250:
  221. pp_bg_4 = pp_bg_4.crop(bbox=(0, pp_bg_4.height - pp_4.height - 250, pp_bg_4.width, pp_bg_4.height))
  222. detailed_images.append(pp_bg_4)
  223. return PictureProcessing(im=self.add_pic(detailed_images))
  224. # 展示产品信息和颜色图
  225. def deal_pic_4(self):
  226. detailed_images = []
  227. pp_bg_1 = PictureProcessing(r"{}\t (7).jpg".format(self.root))
  228. # 粘贴产品信息
  229. # ---添加组合2图片
  230. color_name_list = ["组合2", "组合", "俯视"]
  231. goods_art_no_list = list(self.data.keys())
  232. for color_name in color_name_list:
  233. pp_jpg_1, pp_png_1 = self.image_one_pic(return_orign=True,
  234. goods_art_no=goods_art_no_list[0],
  235. name=color_name,
  236. )
  237. if not pp_png_1:
  238. continue
  239. pp_jpg_1: PictureProcessing
  240. pp_png_1: PictureProcessing
  241. pp_jpg_1 = pp_jpg_1.resize(base_by_box=(589, 416))
  242. pp_png_1 = pp_png_1.resize(base_by_box=(589, 416))
  243. pp_bg_1 = pp_bg_1.to_overlay_pic_advance(top_img=pp_jpg_1, top_png_img=pp_png_1, base="nc", value=(0, 257))
  244. break
  245. # ====添加文字信息
  246. text_list = [{"title": "帮面材质:", "get_text": "鞋面材质"},
  247. {"title": "鞋型:", "get_text": "鞋型"},
  248. {"title": "内里材质:", "get_text": "内里材质"},
  249. {"title": "头型:", "get_text": "头型"},
  250. {"title": "大底材质:", "get_text": "鞋底材质"},
  251. {"title": "货号:", "get_text": "款号"},
  252. ]
  253. x, y = 176, 779
  254. pos_list = [
  255. (x, y),
  256. (x + 592, y),
  257. (x, y + 101),
  258. (x + 592, y + 101),
  259. (x, y + 101 + 101),
  260. (x + 592, y + 101 + 101),
  261. ]
  262. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 34) # 鞋材料信息
  263. n = -1
  264. for text_data in text_list:
  265. text_value = self.get_text_value(text_data["get_text"])
  266. if text_value:
  267. n += 1
  268. text = "{} {}".format(text_data["title"], text_value)
  269. text_image = pp_bg_1.get_text_image_advanced(font=font_1,
  270. text=text,
  271. fill=(0, 0, 0),
  272. return_mode="min_image")
  273. pp_bg_1 = pp_bg_1.paste_img(top_img=text_image, base="nw", value=pos_list[n])
  274. detailed_images.append(pp_bg_1)
  275. # =======添加各个颜色====多余高度需要剪裁
  276. pp_bg_2 = PictureProcessing(r"{}\t (8).jpg".format(self.root))
  277. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 28) # 颜色名称
  278. color_pic_list_1 = []
  279. color_pic_list_2 = []
  280. for goods_art_no_dict in self.goods_no_value["货号资料"]:
  281. color_name = goods_art_no_dict["颜色名称"]
  282. goods_art_no = goods_art_no_dict["货号"]
  283. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  284. goods_art_no=goods_art_no,
  285. name="侧视",
  286. )
  287. pp_jpg: PictureProcessing
  288. pp_jpg = pp_jpg.resize(value=390)
  289. pp_png = pp_png.resize(value=390)
  290. pp_jpg = pp_jpg.paste_img_invert(
  291. top_img=PictureProcessing("RGBA", (pp_jpg.width, pp_jpg.height + 70), (255, 255, 255, 0)),
  292. base="nw"
  293. )
  294. pp_png = pp_png.paste_img_invert(
  295. top_img=PictureProcessing("RGBA", (pp_png.width, pp_png.height + 70), (255, 255, 255, 0)),
  296. base="nw"
  297. )
  298. text_image = pp_bg_2.get_text_image_advanced(font=font_2,
  299. text="{} / COLOR".format(color_name),
  300. fill=(0, 0, 0),
  301. return_mode="min_image")
  302. pp_jpg = pp_jpg.paste_img(top_img=text_image, base="sc", value=(0, 10))
  303. color_pic_list_1.append(pp_jpg)
  304. color_pic_list_2.append(pp_png)
  305. # 颜色列表进行等分展示
  306. all_color_pp_1 = PictureProcessing().horizontal_distribution(color_pic_list_1, bg_width=1114, line_spacing=10,
  307. number_per_row=2)
  308. all_color_pp_2 = PictureProcessing().horizontal_distribution(color_pic_list_2, bg_width=1114, line_spacing=10,
  309. number_per_row=2)
  310. pp_bg_2 = pp_bg_2.to_overlay_pic_advance(top_img=all_color_pp_1, top_png_img=all_color_pp_2, base="nc",
  311. value=(0, 131))
  312. if pp_bg_2.height > all_color_pp_1.height + 131 + 50:
  313. pp_bg_2 = pp_bg_2.crop(
  314. bbox=(0, 0, pp_bg_2.width, all_color_pp_1.height + 181))
  315. detailed_images.append(pp_bg_2)
  316. return PictureProcessing(im=self.add_pic(detailed_images))
  317. # 产品细节
  318. def deal_pic_5(self):
  319. detailed_images = []
  320. detailed_images.append(PictureProcessing(r"{}\t (9).jpg".format(self.root)))
  321. detailed_images.append(PictureProcessing(r"{}\t (10).jpg".format(self.root)))
  322. # ==================俯视图鞋头===============
  323. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60) # 主标题
  324. font_1_color = (1, 1, 1)
  325. font_2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 28) # 副标题
  326. font_2_color = (51, 51, 51)
  327. goods_art_no_list = list(self.data.keys())
  328. view_list = ["俯视", "侧视", "内里", "鞋底"]
  329. for index, view_name in enumerate(view_list):
  330. bg = PictureProcessing(r"{}\t (11).jpg".format(self.root))
  331. text_list = []
  332. text_list.append({"text": self.get_text_value("提示{}主标题".format(index + 1)),
  333. "font": font_1,
  334. "fill": font_1_color,
  335. })
  336. # self.get_text_value("提示{}副标题".format(index + 1))
  337. # text = "副标题副标题副标题副标题副标题副标题副标题副标题\n副标题副标题副标题副标题副标题副标题副标题副标题\n副标题\n副标题\n副标题\n副标题\n副标题"
  338. text_list.append({"text": self.get_text_value("提示{}副标题".format(index + 1)),
  339. "font": font_2,
  340. "fill": font_2_color,
  341. })
  342. text_image = self.add_text_list(text_list, spacing=30, base="nc")
  343. if text_image:
  344. bg = bg.paste_img(
  345. top_img=text_image,
  346. base="nc",
  347. value=(0, 0))
  348. bg = bg.crop(bbox=(0, 0, bg.width, text_image.height + 50))
  349. detailed_images.append(bg)
  350. # ===粘贴图片
  351. pp_1 = self.get_overlay_pic_from_dict(goods_art_no=goods_art_no_list[0],
  352. color_name=view_name,
  353. bg_color=(255, 255, 255)
  354. )
  355. if view_name == "俯视":
  356. resize_value = 1011
  357. paste_img_value = (252, 0)
  358. base = "ws"
  359. if view_name == "侧视":
  360. resize_value = 1253
  361. paste_img_value = (270, 0)
  362. base = "es"
  363. if view_name == "内里":
  364. resize_value = 1539
  365. paste_img_value = (0, 0)
  366. base = "ws"
  367. if view_name == "鞋底":
  368. resize_value = 1104
  369. paste_img_value = (0, 0)
  370. base = "cc"
  371. pp_1 = pp_1.resize(value=resize_value)
  372. pp_1 = pp_1.paste_img_invert(top_img=PictureProcessing("RGB", (1079, 572), (255, 255, 255)),
  373. base=base,
  374. value=paste_img_value
  375. )
  376. bg = PictureProcessing(r"{}\t (11).jpg".format(self.root))
  377. bg = bg.paste_img(top_img=pp_1,
  378. base="nc",
  379. value=(0, 0),
  380. )
  381. bg = bg.crop(bbox=(0, 0, bg.width, pp_1.height + 10))
  382. detailed_images.append(bg)
  383. detailed_images.append(PictureProcessing(r"{}\t (13).jpg".format(self.root)))
  384. return PictureProcessing(im=self.add_pic(detailed_images))
  385. # 组合图展示
  386. def deal_pic_6(self):
  387. flag = False # 判断是否有组合图
  388. detailed_images = []
  389. pp_bg_1 = PictureProcessing(r"{}\t (15).jpg".format(self.root))
  390. detailed_images.append(pp_bg_1)
  391. goods_art_no_list = list(self.data.keys())
  392. goods_art_no = goods_art_no_list[0]
  393. # 组合图1
  394. pp_bg_2 = PictureProcessing(r"{}\t (16).jpg".format(self.root))
  395. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  396. goods_art_no=goods_art_no,
  397. name="组合",
  398. )
  399. if pp_jpg:
  400. flag = True
  401. pp_jpg: PictureProcessing
  402. pp_jpg = pp_jpg.resize(base_by_box=(910 * 0.9, 800 * 0.9))
  403. pp_png = pp_png.resize(base_by_box=(910 * 0.9, 800 * 0.9))
  404. pp_bg_2 = pp_bg_2.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc")
  405. detailed_images.append(pp_bg_2)
  406. # ============组合图2
  407. pp_bg_3 = PictureProcessing(r"{}\t (17).jpg".format(self.root))
  408. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  409. goods_art_no=goods_art_no,
  410. name="组合2",
  411. )
  412. if pp_jpg:
  413. flag = True
  414. pp_jpg: PictureProcessing
  415. pp_jpg = pp_jpg.resize(base_by_box=(937 * 0.9, 827 * 0.9))
  416. pp_png = pp_png.resize(base_by_box=(937 * 0.9, 827 * 0.9))
  417. pp_bg_3 = pp_bg_3.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="nw", value=(124, 446))
  418. detailed_images.append(pp_bg_3)
  419. # ==========组合图3
  420. pp_bg_4 = PictureProcessing(r"{}\t (18).jpg".format(self.root))
  421. detailed_images.append(pp_bg_4)
  422. pp_bg_5 = PictureProcessing(r"{}\t (19).jpg".format(self.root))
  423. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  424. goods_art_no=goods_art_no,
  425. name="组合3",
  426. )
  427. if pp_jpg:
  428. flag = True
  429. pp_jpg: PictureProcessing
  430. pp_jpg = pp_jpg.resize(base_by_box=(1062, 937))
  431. pp_png = pp_png.resize(base_by_box=(1062, 937))
  432. pp_bg_5 = pp_bg_5.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc")
  433. detailed_images.append(pp_bg_5)
  434. if flag:
  435. return PictureProcessing(im=self.add_pic(detailed_images))
  436. else:
  437. return None
  438. # 各个颜色展示
  439. def deal_pic_7(self):
  440. detailed_images = []
  441. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 32) # 副标题
  442. view_list = ["俯视", "侧视", "后跟", "鞋底"]
  443. bg_color = (241, 239, 240)
  444. for goods_art_no_dict in self.goods_no_value["货号资料"]:
  445. bg = PictureProcessing(r"{}\t (20).jpg".format(self.root))
  446. color_name = goods_art_no_dict["颜色名称"]
  447. goods_art_no = goods_art_no_dict["货号"]
  448. # 粘贴颜色名称
  449. text_image = bg.get_text_image_advanced(font=font_1,
  450. text="{}".format(color_name),
  451. fill=(0, 0, 0),
  452. return_mode="min_image")
  453. bg = bg.paste_img(top_img=text_image, base="nw", value=(85, 35))
  454. # 粘贴图片
  455. for view_name in view_list:
  456. pp = self.get_overlay_pic_from_dict(goods_art_no=goods_art_no,
  457. color_name=view_name,
  458. bg_color=bg_color,
  459. )
  460. if view_name == "俯视":
  461. pp = pp.resize(base_by_box=(779 * 0.8, 838 * 0.8))
  462. pp = pp.paste_img_invert(top_img=PictureProcessing("RGB", (779, 836), bg_color), base="cc")
  463. bg = bg.paste_img(top_img=pp, value=(38, 152))
  464. if view_name == "侧视":
  465. pp = pp.resize(base_by_box=(321, 244))
  466. pp = pp.paste_img_invert(top_img=PictureProcessing("RGB", (321, 244), bg_color), base="cc")
  467. bg = bg.paste_img(top_img=pp, value=(844, 152))
  468. if view_name == "后跟":
  469. pp = pp.resize(base_by_box=(321 * 0.7, 278 * 0.9))
  470. pp = pp.paste_img_invert(top_img=PictureProcessing("RGB", (321, 278), bg_color), base="cc")
  471. bg = bg.paste_img(top_img=pp, value=(844, 417))
  472. if view_name == "鞋底":
  473. pp = pp.resize(base_by_box=(321, 270))
  474. pp = pp.paste_img_invert(top_img=PictureProcessing("RGB", (321, 270), bg_color), base="cc")
  475. bg = bg.paste_img(top_img=pp, value=(844, 720))
  476. detailed_images.append(bg)
  477. return PictureProcessing(im=self.add_pic(detailed_images))
  478. # 添加注意事项
  479. def deal_pic_8(self):
  480. detailed_images = []
  481. detailed_images.append(PictureProcessing(r"{}\t (22).jpg".format(self.root)))
  482. return PictureProcessing(im=self.add_pic(detailed_images))
  483. # 添加注意事项
  484. def deal_pic_9(self):
  485. detailed_images = []
  486. detailed_images.append(PictureProcessing(r"{}\t (23).jpg".format(self.root)))
  487. detailed_images.append(PictureProcessing(r"{}\t (24).jpg".format(self.root)))
  488. return PictureProcessing(im=self.add_pic(detailed_images))