detail_huilima5.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 = "huilima-5"
  27. # 乐福鞋 详情页
  28. class DetailPicGet(DetailBase):
  29. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  30. root = r"{}\resources\detail_temp\huilima\5".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\huilima\5".format(os.getcwd())
  54. print("run huilima-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. ]
  64. if test:
  65. self.run_test()
  66. else:
  67. self.run_all()
  68. def run_test(self):
  69. detailed_images = []
  70. detailed_images.append(self.deal_pic_1())
  71. detailed_images.append(self.deal_pic_2())
  72. detailed_images.append(self.deal_pic_3())
  73. detailed_images.append(self.deal_pic_4())
  74. detailed_images.append(self.deal_pic_5())
  75. detailed_images.append(self.deal_pic_6())
  76. img = self.add_pic(detailed_images)
  77. if img:
  78. self.create_folder(r"{}/{}".format(self.out_put_dir, template_name))
  79. img.save(
  80. r"{}/{}/{}.jpg".format(
  81. self.out_put_dir, template_name, self.goods_no, format="JPEG"
  82. )
  83. )
  84. img.show()
  85. #
  86. def deal_pic_1(self):
  87. detailed_images = []
  88. pp_bg_1 = PictureProcessing(r"{}\1.jpg".format(self.root), 1600)
  89. font_main = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 160)
  90. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  91. main_text = self.get_text_value("标题")
  92. sub_text = self.get_text_value("副标题")
  93. _pp = PictureProcessing().get_text_image_advanced(
  94. font=font_main,
  95. text=main_text,
  96. fill=(0, 0, 0),
  97. spacing=20,
  98. return_mode="min_image",
  99. )
  100. _pp_sub = PictureProcessing().get_text_image_advanced(
  101. font=font_sub,
  102. text=sub_text,
  103. fill=(0, 0, 0),
  104. return_mode="min_image",
  105. )
  106. pp_bg_1 = pp_bg_1.paste_img(top_img=_pp, value=(0, 232), base="cs")
  107. pp_bg_1 = pp_bg_1.paste_img(top_img=_pp_sub, value=(0, 446), base="cs")
  108. goods_art_no_list = list(self.data.keys())
  109. pp_jpg_1_list = []
  110. pp_png_1_list = []
  111. pp_jpg, pp_png = self.image_one_pic(
  112. return_orign=True,
  113. goods_art_no=goods_art_no_list[0],
  114. name="俯视",
  115. )
  116. pp_jpg_1_list.append(pp_jpg)
  117. pp_jpg_1_list.append(pp_jpg)
  118. pp_png_1_list.append(pp_png)
  119. pp_png_1_list.append(pp_png)
  120. x, y = 0, 0
  121. pp_bg_jpg = PictureProcessing("RGB", (1600, 1600), (255, 255, 255))
  122. _resize_value = (
  123. pp_bg_1.width if len(pp_jpg_1_list) == 1 else pp_bg_1.width - 300
  124. )
  125. for index, pp_jpg in enumerate(pp_jpg_1_list):
  126. pp_jpg = pp_jpg.resize(value=_resize_value + 100 * index)
  127. pp_bg_jpg = pp_bg_jpg.to_overlay_pic_advance(top_img=pp_jpg, value=(x, y))
  128. x += 180
  129. y += 60
  130. x, y = 0, 0
  131. pp_bg_png = PictureProcessing("RGBA", (1600, 1600), (255, 255, 255, 0))
  132. for index, pp_png in enumerate(pp_png_1_list):
  133. pp_png = pp_png.resize(value=_resize_value + 100 * index)
  134. pp_bg_png = pp_bg_png.paste_img(top_img=pp_png, value=(x, y))
  135. x += 180
  136. y += 60
  137. min_bbox = pp_bg_png.getbbox()
  138. min_bbox = PictureProcessing().expand_bbox(min_bbox)
  139. pp_bg_jpg = pp_bg_jpg.crop(bbox=min_bbox)
  140. pp_bg_png = pp_bg_png.crop(bbox=min_bbox)
  141. pp_bg_1 = pp_bg_1.to_overlay_pic_advance(
  142. top_img=pp_bg_jpg, top_png_img=pp_bg_png, base="cc"
  143. )
  144. detailed_images.append(pp_bg_1)
  145. # detailed_images.append(pp_bg_2)
  146. return PictureProcessing(im=self.add_pic(detailed_images))
  147. # 展示基础信息
  148. def deal_pic_2(self):
  149. detailed_images = []
  150. pp_bg_2 = PictureProcessing(r"{}\2.jpg".format(self.root))
  151. font_1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 130)
  152. font_desc = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 48)
  153. text = self.get_text_value("设计理念-标题")
  154. text_desc = self.get_text_value("设计理念")
  155. _pp = PictureProcessing().get_text_image_advanced(
  156. font=font_1,
  157. text=text,
  158. fill=(0, 0, 0),
  159. return_mode="min_image",
  160. )
  161. _pp_desc = PictureProcessing().get_text_image_advanced(
  162. font=font_desc,
  163. text=text_desc,
  164. fill=(0, 0, 0),
  165. spacing=30,
  166. align="center",
  167. return_mode="min_image",
  168. )
  169. pp_bg_2 = pp_bg_2.paste_img(top_img=_pp, value=(0, 212), base="nc")
  170. pp_bg_2 = pp_bg_2.paste_img(top_img=_pp_desc, value=(0, 533), base="nc")
  171. detailed_images.append(pp_bg_2)
  172. return PictureProcessing(im=self.add_pic(detailed_images))
  173. # 颜色展示
  174. def deal_pic_3(self):
  175. detailed_images = []
  176. pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root))
  177. font_color = ImageFont.truetype(
  178. r"resources\ttf\puhui\Medium.ttf", 34
  179. ) # 颜色名称
  180. color_pic_list_1 = []
  181. for goods_art_no_dict in self.goods_no_value["货号资料"]:
  182. color_name = goods_art_no_dict["颜色名称"]
  183. goods_art_no = goods_art_no_dict["货号"]
  184. pp_jpg = self.get_overlay_pic_from_dict(
  185. goods_art_no=goods_art_no,
  186. color_name="侧视",
  187. bg_color=self.base_bg_color,
  188. )
  189. pp_jpg = pp_jpg.resize(value=pp_bg.width / 2)
  190. pp_jpg = pp_jpg.paste_img_invert(
  191. top_img=PictureProcessing(
  192. "RGBA", (pp_jpg.width, pp_jpg.height + 70), (255, 255, 255, 0)
  193. ),
  194. base="nw",
  195. )
  196. text_image = PictureProcessing().get_text_image_advanced(
  197. font=font_color,
  198. text="{}".format(color_name),
  199. fill=(0, 0, 0),
  200. return_mode="min_image",
  201. )
  202. pp_jpg = pp_jpg.paste_img(top_img=text_image, base="sc", value=(0, 10))
  203. color_pic_list_1.append(pp_jpg)
  204. # 颜色列表进行等分展示
  205. all_color_pp = PictureProcessing().horizontal_distribution(
  206. color_pic_list_1,
  207. bg_width=pp_bg.width - 100,
  208. line_spacing=10,
  209. number_per_row=2,
  210. )
  211. pp_bg.paste_img(top_img=all_color_pp, base="cc", value=(0, -100))
  212. font_category = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  213. text_xiemian = self.get_text_value("鞋面")
  214. text_xiedi = self.get_text_value("鞋底")
  215. text_neili = self.get_text_value("内里")
  216. text_xiedian = self.get_text_value("鞋垫")
  217. pp_text_xiemian = PictureProcessing().get_text_image_advanced(
  218. font=font_category,
  219. text=text_xiemian,
  220. fill=(0, 0, 0),
  221. return_mode="min_image",
  222. )
  223. pp_text_xiedian = PictureProcessing().get_text_image_advanced(
  224. font=font_category,
  225. text=text_xiedian,
  226. fill=(0, 0, 0),
  227. return_mode="min_image",
  228. )
  229. pp_text_xiedi = PictureProcessing().get_text_image_advanced(
  230. font=font_category,
  231. text=text_xiedi,
  232. fill=(0, 0, 0),
  233. return_mode="min_image",
  234. )
  235. pp_text_neili = PictureProcessing().get_text_image_advanced(
  236. font=font_category,
  237. text=text_neili,
  238. fill=(0, 0, 0),
  239. return_mode="min_image",
  240. )
  241. pp_bg = pp_bg.paste_img(top_img=pp_text_xiemian, value=(416, 960), base="nw")
  242. pp_bg = pp_bg.paste_img(top_img=pp_text_xiedian, value=(416, 1144), base="nw")
  243. pp_bg = pp_bg.paste_img(top_img=pp_text_neili, value=(1157, 960), base="nw")
  244. pp_bg = pp_bg.paste_img(top_img=pp_text_xiedi, value=(1157, 1144), base="nw")
  245. detailed_images.append(pp_bg)
  246. return PictureProcessing(im=self.add_pic(detailed_images))
  247. # 展示细节图
  248. def deal_pic_4(self):
  249. detailed_images = []
  250. bg_image = PictureProcessing(r"{}\4.jpg".format(self.root))
  251. text_fill = (255, 255, 255)
  252. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  253. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  254. text_title = self.get_text_value("细节标题-1")
  255. text_sub_title = self.get_text_value("细节副标题-1")
  256. pp_text_title = PictureProcessing().get_text_image_advanced(
  257. font=font_title,
  258. text=text_title,
  259. fill=text_fill,
  260. return_mode="min_image",
  261. )
  262. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  263. font=font_sub,
  264. text=text_sub_title,
  265. fill=text_fill,
  266. return_mode="min_image",
  267. )
  268. bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 258))
  269. bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
  270. goods_art_no_list = list(self.data.keys())
  271. _,pp_png = self.image_one_pic(
  272. return_orign=True,
  273. goods_art_no=goods_art_no_list[0],
  274. name="俯视",
  275. )
  276. pp_png = pp_png.resize(value=bg_image.width * 2.5)
  277. bg_image.paste_img(top_img=pp_png, base="en", value=(0, 800))
  278. detailed_images.append(bg_image)
  279. return PictureProcessing(im=self.add_pic(detailed_images))
  280. # 场景图--产品展示
  281. def deal_pic_5(self):
  282. detailed_images = []
  283. bg_image = PictureProcessing(r"{}\5.jpg".format(self.root))
  284. text_fill = (255, 255, 255)
  285. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  286. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  287. text_title = self.get_text_value("细节标题-2")
  288. text_sub_title = self.get_text_value("细节副标题-2")
  289. pp_text_title = PictureProcessing().get_text_image_advanced(
  290. font=font_title,
  291. text=text_title,
  292. fill=text_fill,
  293. return_mode="min_image",
  294. )
  295. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  296. font=font_sub,
  297. text=text_sub_title,
  298. fill=text_fill,
  299. return_mode="min_image",
  300. )
  301. bg_image.paste_img(top_img=pp_text_title, base="nw", value=(115, 369))
  302. bg_image.paste_img(top_img=pp_text_sub_title, base="nw", value=(115, 686))
  303. goods_art_no_list = list(self.data.keys())
  304. _, pp_png = self.image_one_pic(
  305. return_orign=True,
  306. goods_art_no=goods_art_no_list[0],
  307. name="俯视",
  308. )
  309. pp_png = pp_png.resize(value=bg_image.width * 2)
  310. bg_image.paste_img(top_img=pp_png, base="nw", value=(-100, 700))
  311. detailed_images.append(bg_image)
  312. return PictureProcessing(im=self.add_pic(detailed_images))
  313. # 场景图--产品展示
  314. def deal_pic_6(self):
  315. detailed_images = []
  316. bg_image = PictureProcessing(r"{}\6.jpg".format(self.root))
  317. text_fill = (255, 255, 255)
  318. font_title = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 150)
  319. font_sub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 50)
  320. text_title = self.get_text_value("细节标题-3")
  321. text_sub_title = self.get_text_value("细节副标题-3")
  322. pp_text_title = PictureProcessing().get_text_image_advanced(
  323. font=font_title,
  324. text=text_title,
  325. fill=text_fill,
  326. return_mode="min_image",
  327. )
  328. pp_text_sub_title = PictureProcessing().get_text_image_advanced(
  329. font=font_sub,
  330. text=text_sub_title,
  331. fill=text_fill,
  332. return_mode="min_image",
  333. )
  334. bg_image.paste_img(top_img=pp_text_title, base="en", value=(108, 158))
  335. bg_image.paste_img(top_img=pp_text_sub_title, base="en", value=(108, 578))
  336. goods_art_no_list = list(self.data.keys())
  337. _, pp_png = self.image_one_pic(
  338. return_orign=True,
  339. goods_art_no=goods_art_no_list[0],
  340. name="侧视",
  341. )
  342. pp_png = pp_png.resize(value=bg_image.width * 2.5)
  343. bg_image.paste_img(top_img=pp_png, base="en", value=(0, 700))
  344. detailed_images.append(bg_image)
  345. return PictureProcessing(im=self.add_pic(detailed_images))
  346. # # 添加注意事项
  347. # def deal_pic_6(self):
  348. # detailed_images = []
  349. # detailed_images.append(PictureProcessing(r"{}\20.jpg".format(self.root)))
  350. # detailed_images.append(PictureProcessing(r"{}\21.jpg".format(self.root)))
  351. # return PictureProcessing(im=self.add_pic(detailed_images))