detail_zhudi1.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. from PIL import ImageFont
  9. import sys
  10. import settings
  11. # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
  12. # from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
  13. is_test_plugins = False
  14. try:
  15. is_test_plugins = settings.is_test_plugins
  16. except:
  17. is_test_plugins = False
  18. if is_test_plugins:
  19. from custom_plugins.plugins_mode.detail_generate_base import DetailBase
  20. from custom_plugins.plugins_mode.pic_deal import PictureProcessing
  21. else:
  22. from plugins_mode.detail_generate_base import DetailBase
  23. from plugins_mode.pic_deal import PictureProcessing
  24. plugins_name = "详情模板"
  25. company_name_list = ["全部"]
  26. template_name = "zhudi-1"
  27. # 乐福鞋 详情页
  28. class DetailPicGet(DetailBase):
  29. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  30. root = r"{}\resources\detail_temp\zhudi\1".format(os.getcwd())
  31. def __init__(
  32. self,
  33. goods_no,
  34. goods_no_value: dict,
  35. out_put_dir,
  36. windows=None,
  37. test=False,
  38. excel_data=None,
  39. assigned_page_list=None,
  40. output_queue=None,
  41. **kwargs
  42. ):
  43. super().__init__(
  44. goods_no,
  45. goods_no_value,
  46. out_put_dir,
  47. windows=windows,
  48. excel_data=excel_data,
  49. assigned_page_list=assigned_page_list,
  50. output_queue=output_queue,
  51. )
  52. self.template_name = template_name
  53. self.root = r"{}\resources\detail_temp\zhudi\1".format(os.getcwd())
  54. print("run zhudi-1 ")
  55. self.base_bg_color = (255, 255, 255)
  56. self.deal_pic_func_list = [
  57. self.deal_pic_1,
  58. self.deal_pic_2,
  59. self.deal_pic_3,
  60. self.deal_pic_4,
  61. self.deal_pic_5,
  62. self.deal_pic_6,
  63. self.deal_pic_7,
  64. self.deal_pic_8,
  65. ]
  66. if test:
  67. self.run_test()
  68. else:
  69. self.run_all()
  70. def run_test(self):
  71. detailed_images = []
  72. detailed_images.append(self.deal_pic_1())
  73. detailed_images.append(self.deal_pic_2())
  74. detailed_images.append(self.deal_pic_3())
  75. detailed_images.append(self.deal_pic_4())
  76. detailed_images.append(self.deal_pic_5())
  77. detailed_images.append(self.deal_pic_6())
  78. detailed_images.append(self.deal_pic_7())
  79. detailed_images.append(self.deal_pic_8())
  80. img = self.add_pic(detailed_images)
  81. if img:
  82. self.create_folder(r"{}/{}".format(self.out_put_dir, template_name))
  83. img.save(
  84. r"{}/{}/{}.jpg".format(
  85. self.out_put_dir, template_name, self.goods_no, format="JPEG"
  86. )
  87. )
  88. img.show()
  89. #
  90. def deal_pic_1(self):
  91. detailed_images = []
  92. pp_bg_1 = PictureProcessing(r"{}\1.jpg".format(self.root), 1600)
  93. font_main = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 160)
  94. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  95. main_text = self.get_text_value("标题")
  96. sub_text = self.get_text_value("副标题")
  97. _pp = PictureProcessing().get_text_image_advanced(
  98. font=font_main,
  99. text=main_text,
  100. fill=(0, 0, 0),
  101. spacing=20,
  102. return_mode="min_image",
  103. )
  104. _pp_sub = PictureProcessing().get_text_image_advanced(
  105. font=font_sub,
  106. text=sub_text,
  107. fill=(0, 0, 0),
  108. return_mode="min_image",
  109. )
  110. pp_bg_1 = pp_bg_1.paste_img(top_img=_pp, value=(0, 232), base="cs")
  111. pp_bg_1 = pp_bg_1.paste_img(top_img=_pp_sub, value=(0, 446), base="cs")
  112. goods_art_no_list = list(self.data.keys())
  113. pp_jpg, pp_png = self.image_one_pic(
  114. return_orign=True,
  115. goods_art_no=goods_art_no_list[0],
  116. name="俯视",
  117. )
  118. if not pp_jpg:
  119. return
  120. _resize_value = pp_bg_1.width
  121. pp_jpg = pp_jpg.resize(value=_resize_value)
  122. pp_png = pp_png.resize(value=_resize_value)
  123. pp_bg_1 = pp_bg_1.to_overlay_pic_advance(
  124. top_img=pp_jpg, top_png_img=pp_png, base="cc", value=(0, -100)
  125. )
  126. detailed_images.append(pp_bg_1)
  127. # detailed_images.append(pp_bg_2)
  128. return PictureProcessing(im=self.add_pic(detailed_images))
  129. # 展示基础信息
  130. def deal_pic_2(self):
  131. detailed_images = []
  132. pp_bg_2 = PictureProcessing(r"{}\2.jpg".format(self.root))
  133. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 130)
  134. font_desc = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 48)
  135. text = self.get_text_value("设计理念-标题")
  136. text_desc = self.get_text_value("设计理念")
  137. _pp = PictureProcessing().get_text_image_advanced(
  138. font=font_1,
  139. text=text,
  140. fill=(0, 0, 0),
  141. return_mode="min_image",
  142. )
  143. _pp_desc = PictureProcessing().get_text_image_advanced(
  144. font=font_desc,
  145. text=text_desc,
  146. fill=(0, 0, 0),
  147. spacing=30,
  148. align="center",
  149. return_mode="min_image",
  150. )
  151. pp_bg_2 = pp_bg_2.paste_img(top_img=_pp, value=(0, 212), base="nc")
  152. pp_bg_2 = pp_bg_2.paste_img(top_img=_pp_desc, value=(0, 533), base="nc")
  153. detailed_images.append(pp_bg_2)
  154. return PictureProcessing(im=self.add_pic(detailed_images))
  155. # 颜色展示
  156. def deal_pic_3(self):
  157. detailed_images = []
  158. pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root))
  159. font_color = ImageFont.truetype(
  160. r"resources\ttf\puhui\Medium.ttf", 34
  161. ) # 颜色名称
  162. color_pic_list_1 = []
  163. for goods_art_no_dict in self.goods_no_value["货号资料"]:
  164. color_name = goods_art_no_dict["颜色名称"]
  165. goods_art_no = goods_art_no_dict["货号"]
  166. pp_jpg = self.get_overlay_pic_from_dict(
  167. goods_art_no=goods_art_no,
  168. color_name="侧视",
  169. bg_color=self.base_bg_color,
  170. )
  171. pp_jpg = pp_jpg.resize(value=pp_bg.width / 2)
  172. pp_jpg = pp_jpg.paste_img_invert(
  173. top_img=PictureProcessing(
  174. "RGBA", (pp_jpg.width, pp_jpg.height + 70), (255, 255, 255, 0)
  175. ),
  176. base="nw",
  177. )
  178. text_image = PictureProcessing().get_text_image_advanced(
  179. font=font_color,
  180. text="{}".format(color_name),
  181. fill=(0, 0, 0),
  182. return_mode="min_image",
  183. )
  184. pp_jpg = pp_jpg.paste_img(top_img=text_image, base="sc", value=(0, 10))
  185. color_pic_list_1.append(pp_jpg)
  186. # 颜色列表进行等分展示
  187. all_color_pp = PictureProcessing().horizontal_distribution(
  188. color_pic_list_1,
  189. bg_width=pp_bg.width - 100,
  190. line_spacing=10,
  191. number_per_row=2,
  192. )
  193. pp_bg.paste_img(top_img=all_color_pp, base="cc", value=(0, -100))
  194. font_category = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  195. text_xiemian = self.get_text_value("鞋面")
  196. text_xiedi = self.get_text_value("鞋底")
  197. text_neili = self.get_text_value("内里")
  198. text_xiedian = self.get_text_value("鞋垫")
  199. pp_text_xiemian = PictureProcessing().get_text_image_advanced(
  200. font=font_category,
  201. text=text_xiemian,
  202. fill=(0, 0, 0),
  203. return_mode="min_image",
  204. )
  205. pp_text_xiedian = PictureProcessing().get_text_image_advanced(
  206. font=font_category,
  207. text=text_xiedian,
  208. fill=(0, 0, 0),
  209. return_mode="min_image",
  210. )
  211. pp_text_xiedi = PictureProcessing().get_text_image_advanced(
  212. font=font_category,
  213. text=text_xiedi,
  214. fill=(0, 0, 0),
  215. return_mode="min_image",
  216. )
  217. pp_text_neili = PictureProcessing().get_text_image_advanced(
  218. font=font_category,
  219. text=text_neili,
  220. fill=(0, 0, 0),
  221. return_mode="min_image",
  222. )
  223. pp_bg = pp_bg.paste_img(top_img=pp_text_xiemian, value=(416, 960), base="nw")
  224. pp_bg = pp_bg.paste_img(top_img=pp_text_xiedian, value=(416, 1144), base="nw")
  225. pp_bg = pp_bg.paste_img(top_img=pp_text_neili, value=(1157, 960), base="nw")
  226. pp_bg = pp_bg.paste_img(top_img=pp_text_xiedi, value=(1157, 1144), base="nw")
  227. detailed_images.append(pp_bg)
  228. return PictureProcessing(im=self.add_pic(detailed_images))
  229. # 展示细节图
  230. def deal_pic_4(self):
  231. detailed_images = []
  232. bg_image = PictureProcessing(r"{}\4.jpg".format(self.root))
  233. text_fill = (255, 255, 255)
  234. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  235. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  236. text_title = self.get_text_value("细节标题-1")
  237. text_sub_title = self.get_text_value("细节副标题-1")
  238. pp_text_title = PictureProcessing().get_text_image_advanced(
  239. font=font_title,
  240. text=text_title,
  241. fill=text_fill,
  242. return_mode="min_image",
  243. )
  244. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  245. font=font_sub,
  246. text=text_sub_title,
  247. fill=text_fill,
  248. return_mode="min_image",
  249. )
  250. bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 258))
  251. bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
  252. goods_art_no_list = list(self.data.keys())
  253. _, pp_png = self.image_one_pic(
  254. return_orign=True,
  255. goods_art_no=goods_art_no_list[0],
  256. name="俯视",
  257. )
  258. pp_png = pp_png.resize(value=bg_image.width * 2)
  259. pp_png = pp_png.transpose()
  260. bg_image.paste_img(top_img=pp_png, base="cs", value=(-pp_png.width / 4, -200))
  261. detailed_images.append(bg_image)
  262. return PictureProcessing(im=self.add_pic(detailed_images))
  263. # 场景图--产品展示
  264. def deal_pic_5(self):
  265. detailed_images = []
  266. bg_image = PictureProcessing(r"{}\5.jpg".format(self.root))
  267. text_fill = (255, 255, 255)
  268. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  269. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  270. text_title = self.get_text_value("细节标题-2")
  271. text_sub_title = self.get_text_value("细节副标题-2")
  272. pp_text_title = PictureProcessing().get_text_image_advanced(
  273. font=font_title,
  274. text=text_title,
  275. fill=text_fill,
  276. return_mode="min_image",
  277. )
  278. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  279. font=font_sub,
  280. text=text_sub_title,
  281. fill=text_fill,
  282. return_mode="min_image",
  283. )
  284. bg_image.paste_img(top_img=pp_text_title, base="nw", value=(115, 369))
  285. bg_image.paste_img(top_img=pp_text_sub_title, base="nw", value=(115, 686))
  286. goods_art_no_list = list(self.data.keys())
  287. _, pp_png = self.image_one_pic(
  288. return_orign=True,
  289. goods_art_no=goods_art_no_list[0],
  290. name="俯视",
  291. )
  292. pp_png = pp_png.resize(value=bg_image.width * 2)
  293. pp_png = pp_png.transpose()
  294. bg_image.paste_img(top_img=pp_png, base="cs", value=(pp_png.width / 4, 0))
  295. detailed_images.append(bg_image)
  296. return PictureProcessing(im=self.add_pic(detailed_images))
  297. # 场景图--产品展示
  298. def deal_pic_6(self):
  299. detailed_images = []
  300. bg_image = PictureProcessing(r"{}\6.jpg".format(self.root))
  301. text_fill = (255, 255, 255)
  302. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  303. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  304. text_title = self.get_text_value("细节标题-3")
  305. text_sub_title = self.get_text_value("细节副标题-3")
  306. pp_text_title = PictureProcessing().get_text_image_advanced(
  307. font=font_title,
  308. text=text_title,
  309. fill=text_fill,
  310. return_mode="min_image",
  311. )
  312. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  313. font=font_sub,
  314. text=text_sub_title,
  315. fill=text_fill,
  316. return_mode="min_image",
  317. )
  318. bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 158))
  319. bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
  320. goods_art_no_list = list(self.data.keys())
  321. _, pp_png = self.image_one_pic(
  322. return_orign=True,
  323. goods_art_no=goods_art_no_list[0],
  324. name="内里",
  325. )
  326. pp_png = pp_png.resize(value=bg_image.width * 2)
  327. bg_image.paste_img(top_img=pp_png, base="cs", value=(-pp_png.width / 3.5, 100))
  328. detailed_images.append(bg_image)
  329. return PictureProcessing(im=self.add_pic(detailed_images))
  330. # 场景图--产品展示
  331. def deal_pic_7(self):
  332. detailed_images = []
  333. top_image = PictureProcessing(r"{}\7.jpg".format(self.root))
  334. text_fill = (0, 0, 0)
  335. font_title = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 60)
  336. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 40)
  337. detailed_images.append(top_image)
  338. goods_art_no_list = list(self.data.keys())
  339. for goods_info in goods_art_no_list:
  340. pp_jpg_1_list = []
  341. pp_png_1_list = []
  342. for goods_item in goods_art_no_list:
  343. pp_jpg, pp_png = self.image_one_pic(
  344. return_orign=True,
  345. goods_art_no=goods_item,
  346. name="俯视",
  347. )
  348. pp_jpg_1_list.append(pp_jpg)
  349. pp_png_1_list.append(pp_png)
  350. x, y = 0, 0
  351. pp_bg_jpg = PictureProcessing("RGB", (1600, 1600), (255, 255, 255))
  352. _resize_value = (
  353. top_image.width if len(pp_jpg_1_list) == 1 else top_image.width - 300
  354. )
  355. for index, pp_jpg in enumerate(pp_jpg_1_list):
  356. pp_jpg = pp_jpg.resize(value=_resize_value + 100 * index)
  357. pp_bg_jpg = pp_bg_jpg.to_overlay_pic_advance(
  358. top_img=pp_jpg, value=(x, y)
  359. )
  360. x += 180
  361. y += 60
  362. x, y = 0, 0
  363. pp_bg_png = PictureProcessing("RGBA", (1600, 1600), (255, 255, 255, 0))
  364. for index, pp_png in enumerate(pp_png_1_list):
  365. pp_png = pp_png.resize(value=_resize_value + 100 * index)
  366. pp_bg_png = pp_bg_png.paste_img(top_img=pp_png, value=(x, y))
  367. x += 180
  368. y += 60
  369. min_bbox = pp_bg_png.getbbox()
  370. min_bbox = PictureProcessing().expand_bbox(min_bbox)
  371. pp_bg_jpg = pp_bg_jpg.crop(bbox=min_bbox)
  372. pp_bg_png = pp_bg_png.crop(bbox=min_bbox)
  373. pp_bg_1 = PictureProcessing(
  374. "RGB", (top_image.width, pp_bg_jpg.height), (255, 255, 255)
  375. )
  376. pp_bg_1 = pp_bg_1.to_overlay_pic_advance(
  377. top_img=pp_bg_jpg, top_png_img=pp_bg_png, base="cc"
  378. )
  379. pp_text_title = PictureProcessing().get_text_image_advanced(
  380. font=font_title,
  381. text="45°侧视/SIDE",
  382. fill=text_fill,
  383. return_mode="min_image",
  384. )
  385. pp_bg_1.paste_img(top_img=pp_text_title, base="cs", value=(0, 0))
  386. color_pic_list_1 = []
  387. pp_jpg_ceshi, pp_png_ceshi = self.image_one_pic(
  388. return_orign=True,
  389. goods_art_no=goods_item,
  390. name="侧视",
  391. )
  392. pp_jpg_hougen, pp_png_hougen = self.image_one_pic(
  393. return_orign=True,
  394. goods_art_no=goods_item,
  395. name="后跟",
  396. )
  397. pp_jpg_neili, pp_png_neili = self.image_one_pic(
  398. return_orign=True,
  399. goods_art_no=goods_item,
  400. name="内里",
  401. )
  402. pp_jpg_xiedi, pp_png_xiedi = self.image_one_pic(
  403. return_orign=True,
  404. goods_art_no=goods_item,
  405. name="鞋底",
  406. )
  407. pp_png_ceshi = pp_png_ceshi.resize(value=pp_bg_jpg.width / 3)
  408. text_image = PictureProcessing().get_text_image_advanced(
  409. font=font_sub,
  410. text="180°侧面/SIDE",
  411. fill=(0, 0, 0),
  412. return_mode="min_image",
  413. )
  414. backImage = PictureProcessing(
  415. "RGB", (top_image.width / 2, 400), (255, 255, 255)
  416. )
  417. backImage.paste_img(top_img=text_image, base="cs", value=(0, 0))
  418. backImage.paste_img(top_img=pp_png_ceshi, base="cs", value=(0, 30))
  419. color_pic_list_1.append(backImage)
  420. pp_png_hougen = pp_png_hougen.resize(value=pp_bg_jpg.width / 4.5)
  421. text_image = PictureProcessing().get_text_image_advanced(
  422. font=font_sub,
  423. text="背面/BACK",
  424. fill=(0, 0, 0),
  425. return_mode="min_image",
  426. )
  427. backImage = PictureProcessing(
  428. "RGB", (top_image.width / 2, 400), (255, 255, 255)
  429. )
  430. backImage.paste_img(top_img=text_image, base="cs", value=(0, 0))
  431. backImage.paste_img(top_img=pp_png_hougen, base="cs", value=(0, 30))
  432. color_pic_list_1.append(backImage)
  433. pp_png_neili = pp_png_neili.resize(value=pp_bg_jpg.width / 3)
  434. text_image = PictureProcessing().get_text_image_advanced(
  435. font=font_sub,
  436. text="鞋面/VAMP",
  437. fill=(0, 0, 0),
  438. return_mode="min_image",
  439. )
  440. backImage = PictureProcessing(
  441. "RGB", (top_image.width / 2, 400), (255, 255, 255)
  442. )
  443. backImage.paste_img(top_img=text_image, base="cs", value=(-10, 0))
  444. backImage.paste_img(top_img=pp_png_neili, base="cs", value=(-10, 30))
  445. color_pic_list_1.append(backImage)
  446. pp_png_xiedi = pp_png_xiedi.resize(value=pp_bg_jpg.width / 3)
  447. text_image = PictureProcessing().get_text_image_advanced(
  448. font=font_sub,
  449. text="鞋底/BOTTOM",
  450. fill=(0, 0, 0),
  451. return_mode="min_image",
  452. )
  453. backImage = PictureProcessing(
  454. "RGB", (top_image.width / 2, 400), (255, 255, 255)
  455. )
  456. backImage.paste_img(top_img=text_image, base="cs", value=(0, 0))
  457. backImage.paste_img(top_img=pp_png_xiedi, base="cs", value=(0, 30))
  458. color_pic_list_1.append(backImage)
  459. all_color_pp = PictureProcessing(
  460. "RGB", (top_image.width, 1600), (255, 255, 255)
  461. ).horizontal_distribution(
  462. color_pic_list_1,
  463. bg_width=top_image.width,
  464. line_spacing=10,
  465. number_per_row=2,
  466. )
  467. detailed_images.append(pp_bg_1)
  468. detailed_images.append(all_color_pp)
  469. bottomImage = PictureProcessing(
  470. "RGB", (top_image.width, 200), (255, 255, 255)
  471. )
  472. detailed_images.append(bottomImage)
  473. return PictureProcessing(im=self.add_pic(detailed_images))
  474. # # 添加注意事项
  475. def deal_pic_8(self):
  476. detailed_images = []
  477. detailed_images.append(PictureProcessing(r"{}\10.jpg".format(self.root)))
  478. return PictureProcessing(im=self.add_pic(detailed_images))