detail_xiaosushuoxie7.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. """
  2. 步骤:
  3. 1、整理需要处理的款号图-输出款号图文件夹
  4. 2、整理所有相关的图片作为素材图
  5. 3、按要求进行拼接
  6. """
  7. import os
  8. import re
  9. import settings
  10. from PIL import ImageFont
  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. try:
  14. is_test_plugins = settings.is_test_plugins
  15. except:
  16. is_test_plugins = False
  17. if is_test_plugins:
  18. from custom_plugins.plugins_mode.detail_generate_base import DetailBase
  19. from custom_plugins.plugins_mode.pic_deal import PictureProcessing
  20. else:
  21. from plugins_mode.detail_generate_base import DetailBase
  22. from plugins_mode.pic_deal import PictureProcessing
  23. from PIL import Image, ImageDraw
  24. plugins_name = "详情模板"
  25. company_name_list = ["小苏"]
  26. template_name = "xiaosushuoxie-7"
  27. class DetailPicGet(DetailBase):
  28. need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"]
  29. root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd())
  30. def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False,excel_data=None,assigned_page_list=None):
  31. super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows,excel_data=excel_data,assigned_page_list=assigned_page_list)
  32. self.root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd())
  33. self.template_name = template_name
  34. self.base_bg_color = (236, 226, 211)
  35. self.white_bg_color = (255, 255, 255)
  36. self.black_bg_color = (0, 0, 0)
  37. self.getExtendImages()
  38. self.deal_pic_func_list = [
  39. self.deal_pic_1,
  40. self.deal_pic_2,
  41. self.deal_pic_3,
  42. self.deal_pic_4,
  43. self.deal_pic_5,
  44. self.deal_pic_6,
  45. self.deal_pic_7,
  46. self.deal_pic_8,
  47. self.deal_pic_9,
  48. self.deal_pic_10,
  49. self.deal_pic_11,
  50. ]
  51. if test:
  52. self.run_test()
  53. else:
  54. self.run_all()
  55. def collect_images_by_rules(self,directory_path):
  56. """
  57. 根据规则收集图片:
  58. - '封面图' 和 '上脚图' 各只取一张(如果有多张则取第一张)
  59. - '模特图' 可能有多张(包括模特图、模特图2、模特图3等)
  60. """
  61. collected_images = {
  62. '封面图': None,
  63. '上脚图': None,
  64. '场景图': None,
  65. '模特图': [] # 存储所有模特图
  66. }
  67. for filename in os.listdir(directory_path):
  68. file_path = os.path.join(directory_path, filename)
  69. if os.path.isfile(file_path):
  70. name_part, ext = os.path.splitext(filename)
  71. if ext.lower() in ['.jpg', '.jpeg', '.png', '.gif', '.bmp']:
  72. # 处理封面图
  73. if name_part == '封面图' and collected_images['封面图'] is None:
  74. collected_images['封面图'] = file_path
  75. # 处理上脚图
  76. elif name_part == '上脚图' and collected_images['上脚图'] is None:
  77. collected_images['上脚图'] = file_path
  78. # 处理场景图
  79. elif name_part == '场景图' and collected_images['场景图'] is None:
  80. collected_images['场景图'] = file_path
  81. # 处理模特图(包括模特图、模特图2、模特图3等)
  82. elif name_part.startswith('模特图'):
  83. # 验证是否是模特图的正确格式(模特图 或 模特图+数字)
  84. if name_part == '模特图' or re.match(r'^模特图\d+$', name_part):
  85. collected_images['模特图'].append(file_path)
  86. return collected_images
  87. def getExtendImages(self):
  88. # 增加逻辑,获取任意货号下的组合图
  89. self.extendImages = {}
  90. goods_art_no_list = list(self.data.keys())
  91. for goods_art_no in goods_art_no_list:
  92. _, path = next(iter(self.data[goods_art_no]["pics"].items()))
  93. parent_path = os.path.dirname(os.path.dirname(path))
  94. new_dir = "拓展"
  95. extends_path = os.path.join(parent_path, new_dir)
  96. if not os.path.isdir(extends_path):
  97. continue
  98. images = self.collect_images_by_rules(extends_path)
  99. if self.extendImages:
  100. continue
  101. self.extendImages = images
  102. print("self.extendImages",self.extendImages)
  103. def run_test(self):
  104. detailed_images = []
  105. detailed_images.append(self.deal_pic_1())
  106. detailed_images.append(self.deal_pic_2())
  107. detailed_images.append(self.deal_pic_3())
  108. detailed_images.append(self.deal_pic_4())
  109. detailed_images.append(self.deal_pic_5())
  110. detailed_images.append(self.deal_pic_6())
  111. detailed_images.append(self.deal_pic_7())
  112. detailed_images.append(self.deal_pic_8())
  113. detailed_images.append(self.deal_pic_9())
  114. detailed_images.append(self.deal_pic_10())
  115. detailed_images.append(self.deal_pic_11())
  116. img = self.add_pic(detailed_images)
  117. img.save(r"{}/{}.jpg".format(self.out_put_dir,self.goods_no, format="JPEG"))
  118. def deal_pic_1(self):
  119. """ 制作主图 """
  120. detailed_images = []
  121. cover_image = self.extendImages.get("封面图")
  122. pp_bg = PictureProcessing(r"{}\first_bg.png".format(self.root))
  123. # -------粘贴文字-------
  124. mainTitle = self.get_text_value("主标题")
  125. subTitle = self.get_text_value("副标题")
  126. signTitle = self.get_text_value("签名")
  127. fontMain = ImageFont.truetype(r"resources\ttf\DOUYINSANSBOLD.ttf", 240)
  128. fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 40)
  129. fontSign = ImageFont.truetype(r"resources\ttf\puhui\en\Bold.otf", 40)
  130. main_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  131. main_text_bg = main_text_bg.get_text_image_advanced(
  132. value=(0, 0),
  133. font=fontMain,
  134. text=mainTitle,
  135. align="center",
  136. fill=self.white_bg_color,
  137. spacing=5,
  138. return_mode="min_image",
  139. )
  140. # 副标题
  141. sub_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  142. sub_text_bg = sub_text_bg.get_text_image_advanced(
  143. value=(0, 0),
  144. font=fontSub,
  145. text=subTitle,
  146. align="center",
  147. fill=self.white_bg_color,
  148. spacing=5,
  149. return_mode="min_image",
  150. )
  151. # 签名
  152. sign_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0))
  153. sign_text_bg = sign_text_bg.get_text_image_advanced(
  154. value=(0, 0),
  155. font=fontSign,
  156. text=signTitle,
  157. align="center",
  158. fill=self.white_bg_color,
  159. spacing=5,
  160. return_mode="min_image",
  161. )
  162. pp_bg = pp_bg.paste_img(top_img=main_text_bg,value=(0,208),base='nc')
  163. pp_bg = pp_bg.paste_img(top_img=sub_text_bg,value=(0,470),base='nc')
  164. pp_bg = pp_bg.paste_img(top_img=sign_text_bg,value=(0,57),base='nc')
  165. bottom_bg = PictureProcessing(
  166. r"{}\bolang.png".format(
  167. self.root
  168. )
  169. )
  170. pp_bg.paste_img(top_img=bottom_bg, value=(0, 0),base='cs')
  171. if cover_image:
  172. cover_image_pp = PictureProcessing(cover_image)
  173. cover_image_pp = cover_image_pp.resize(value=(pp_bg.width))
  174. pp_bg = pp_bg.resize(value=(cover_image_pp.height),base='high')
  175. cover_image_pp.paste_img(top_img=pp_bg, value=(0, 0),base='cs')
  176. detailed_images.append(cover_image_pp)
  177. else:
  178. detailed_images.append(pp_bg)
  179. return PictureProcessing(im=self.add_pic(detailed_images))
  180. def deal_pic_2(self):
  181. """
  182. 细节解析
  183. """
  184. # 文字排列
  185. detailed_images = []
  186. top_bg = PictureProcessing(
  187. r"{}\bolang.png".format(
  188. self.root
  189. )
  190. )
  191. # detailed_images.append(top_bg)
  192. designText1 = self.get_text_value("设计理念1")
  193. designText2 = self.get_text_value("设计理念2")
  194. designText3 = self.get_text_value("设计理念3")
  195. fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 60)
  196. centerDesign = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 65)
  197. first_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  198. first_text_bg = first_text_bg.get_text_image_advanced(
  199. value=(0, 0),
  200. font=fontSub,
  201. text=designText1,
  202. align="center",
  203. fill=self.black_bg_color,
  204. return_mode="min_image",
  205. )
  206. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  207. temp_text_bg = temp_text_bg.paste_img(top_img=first_text_bg,value=(0,0),base='cc')
  208. detailed_images.append(temp_text_bg)
  209. second_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  210. second_text_bg = second_text_bg.get_text_image_advanced(
  211. value=(0, 0),
  212. font=centerDesign,
  213. text=designText2,
  214. align="center",
  215. fill=self.black_bg_color,
  216. return_mode="min_image",
  217. )
  218. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  219. temp_text_bg = temp_text_bg.paste_img(top_img=second_text_bg,value=(0,0),base='cc')
  220. detailed_images.append(temp_text_bg)
  221. third_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  222. third_text_bg = third_text_bg.get_text_image_advanced(
  223. value=(0, 0),
  224. font=fontSub,
  225. text=designText3,
  226. align="center",
  227. fill=self.black_bg_color,
  228. return_mode="min_image",
  229. )
  230. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  231. temp_text_bg = temp_text_bg.paste_img(top_img=third_text_bg,value=(0,0),base='cc')
  232. detailed_images.append(temp_text_bg)
  233. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  234. detailed_images.append(temp_text_bg)
  235. # 卡片
  236. pp_list_1 = []
  237. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60)
  238. fontEN = ImageFont.truetype(r"resources\ttf\puhui\en\Medium.otf", 30)
  239. goods_art_no_list = list(self.data.keys())
  240. pp_jpg = self.get_overlay_pic_from_dict(
  241. goods_art_no=goods_art_no_list[0],
  242. color_name="俯视",
  243. bg_color=self.white_bg_color,
  244. )
  245. pp_jpg = pp_jpg.resize(value=840)
  246. text_array = [{"title":self.get_text_value("鞋跟描述")
  247. ,"bottom":"Comfortable heel","position":(-200, 0)},
  248. {"title":self.get_text_value("鞋头描述"),
  249. "position":(200, 0),"bottom":"Versatile Upper"}]
  250. for index, item in enumerate(text_array):
  251. text_bg = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0))
  252. text_bg = text_bg.get_text_image_advanced(
  253. value=(0, 0),
  254. font=font,
  255. text="{}".format(item["title"]),
  256. align="center",
  257. spacing=15,
  258. fill=(255, 255, 255),
  259. return_mode="min_image",
  260. margins=(10, 5, 0, 0),
  261. max_len_one_line=6
  262. )
  263. _bg = PictureProcessing("RGB", (520, 880), (208, 186, 162))
  264. _bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60)
  265. _bg = _bg.paste_img(top_img=text_bg, value=(0, 50),base='nc')
  266. text_bottome = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0))
  267. text_bottome = text_bottome.get_text_image_advanced(
  268. value=(0, 0),
  269. font=fontEN,
  270. text="{}".format(item["bottom"]),
  271. align="center",
  272. spacing=15,
  273. fill=(255, 255, 255),
  274. return_mode="min_image",
  275. margins=(10, 5, 0, 0),
  276. )
  277. _bg = _bg.paste_img(top_img=text_bottome, value=(0, 50),base='cs')
  278. # 第一张图
  279. first_imageBg = PictureProcessing("RGB", (420, 600), self.white_bg_color)
  280. first_imageBg.paste_img(top_img=pp_jpg, value=item["position"], base='cc')
  281. _bg = _bg.paste_img(top_img=first_imageBg, value=(0, 0),base='cc')
  282. pp_list_1.append(_bg)
  283. rows = 2
  284. shoes_bg = PictureProcessing().horizontal_distribution(
  285. pp_list=pp_list_1,
  286. bg_width=top_bg.width,
  287. margins=(0, 0, 50, 50),
  288. line_spacing=60,
  289. number_per_row=rows,
  290. )
  291. detailed_images.append(shoes_bg)
  292. temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color)
  293. detailed_images.append(temp_text_bg)
  294. return PictureProcessing(im=self.add_pic(detailed_images))
  295. def deal_pic_3(self):
  296. detailed_images = []
  297. pp_bg = PictureProcessing(
  298. r"{}\template_4.jpg".format(
  299. self.root
  300. )
  301. )
  302. scene_image = self.extendImages.get("场景图")
  303. _bg = PictureProcessing("RGB", (pp_bg.width*0.8, pp_bg.height*0.86), self.white_bg_color)
  304. _bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60)
  305. font1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 100)
  306. font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  307. text_bg = PictureProcessing("RGB", (440, 200), (255, 255, 255))
  308. text1 = self.get_text_value("面料FAB1")
  309. if not text1:
  310. text1 = "轻盈透气"
  311. text_bg = text_bg.get_text_image_advanced(
  312. value=(0, 0),
  313. font=font1,
  314. text=text1,
  315. align="left",
  316. spacing=5,
  317. fill=(194, 189, 167),
  318. return_mode="min_image",
  319. )
  320. _bg.paste_img(top_img=text_bg, value=(50, 40),base='nw')
  321. # text2
  322. text2 = self.get_text_value("面料FAB2")
  323. if not text2:
  324. text2 = "(软弹不易累脚)"
  325. text_bg2 = PictureProcessing("RGB", (440, 200), (255, 255, 255))
  326. text_bg2 = text_bg2.get_text_image_advanced(
  327. value=(0, 0),
  328. font=font2,
  329. text=text2,
  330. align="left",
  331. spacing=5,
  332. fill=(194, 189, 167),
  333. return_mode="min_image",
  334. )
  335. _bg.paste_img(top_img=text_bg2, value=(50, 120),base='en')
  336. # scene_image
  337. if scene_image:
  338. scene_image_pp = PictureProcessing(scene_image)
  339. scene_image_pp = scene_image_pp.resize(value=round(_bg.width*0.85))
  340. _bg.paste_img(top_img=scene_image_pp, value=(0, _bg.height*0.05),base='cs')
  341. pp_bg = pp_bg.paste_img(top_img=_bg, value=(0, 0),base='cc')
  342. detailed_images.append(pp_bg)
  343. return PictureProcessing(im=self.add_pic(detailed_images))
  344. def deal_pic_4(self):
  345. # =============设计理念================
  346. detail_images = []
  347. top_bg = PictureProcessing(r"{}\template_5.jpg".format(self.root))
  348. goods_art_no_list = list(self.data.keys())
  349. pp_jpg, pp_png = self.image_one_pic(return_orign=True,
  350. goods_art_no=goods_art_no_list[0],
  351. name="俯视",
  352. )
  353. pp_jpg = pp_jpg.resize(value=round(top_bg.width*0.8))
  354. pp_png = pp_png.resize(value=round(top_bg.width*0.8))
  355. top_bg = top_bg.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc",value=(0, 0))
  356. #
  357. textTitle1 = self.get_text_value("材质FAB1")
  358. textTitle2 = self.get_text_value("材质FAB2")
  359. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 100)
  360. font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60)
  361. font3 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
  362. titleBg = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  363. titleBg = titleBg.get_text_image_advanced(
  364. value=(0, 0),
  365. font=font,
  366. text=textTitle1,
  367. align="left",
  368. spacing=5,
  369. fill=(53, 49, 48),
  370. return_mode="min_image",
  371. )
  372. top_bg.paste_img(top_img=titleBg, value=(0, 100),base='nc')
  373. text_bg2 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  374. text_bg2 = titleBg.get_text_image_advanced(
  375. value=(0, 0),
  376. font=font2,
  377. text=textTitle2,
  378. align="left",
  379. spacing=5,
  380. fill=(53, 49, 48),
  381. return_mode="min_image",
  382. )
  383. top_bg.paste_img(top_img=text_bg2, value=(0, 230),base='nc')
  384. textTitle3 = self.get_text_value("材质FAB3")
  385. text_bg3 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  386. text_bg3 = text_bg3.get_text_image_advanced(
  387. value=(0, 0),
  388. font=font3,
  389. text=textTitle3,
  390. align="center",
  391. spacing=5,
  392. fill=(53, 49, 48),
  393. return_mode="min_image",
  394. max_len_one_line=4
  395. )
  396. top_bg.paste_img(top_img=text_bg3, value=(154, 1325),base='nw')
  397. textTitle4 = self.get_text_value("材质FAB4")
  398. text_bg4 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  399. text_bg4 = text_bg4.get_text_image_advanced(
  400. value=(0, 0),
  401. font=font3,
  402. text=textTitle4,
  403. align="center",
  404. spacing=5,
  405. fill=(53, 49, 48),
  406. return_mode="min_image",
  407. max_len_one_line=4
  408. )
  409. top_bg.paste_img(top_img=text_bg4, value=(0, 1325),base='nc')
  410. textTitle5 = self.get_text_value("材质FAB5")
  411. text_bg5 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255))
  412. text_bg5 = text_bg5.get_text_image_advanced(
  413. value=(0, 0),
  414. font=font3,
  415. text=textTitle5,
  416. align="center",
  417. spacing=5,
  418. fill=(53, 49, 48),
  419. return_mode="min_image",
  420. max_len_one_line=4
  421. )
  422. top_bg.paste_img(top_img=text_bg5, value=(154, 1325),base='en')
  423. detail_images.append(top_bg)
  424. return PictureProcessing(im=self.add_pic(detail_images))
  425. def deal_pic_5(self):
  426. detailed_images = []
  427. top_bg = PictureProcessing(
  428. r"{}\template_6.jpg".format(
  429. self.root
  430. )
  431. )
  432. upper_footer_image = self.extendImages.get("上脚图")
  433. if upper_footer_image:
  434. upper_footer_pp = PictureProcessing(upper_footer_image)
  435. upper_footer_pp = upper_footer_pp.resize(value=round(top_bg.height*0.9),base='high')
  436. gengao_fab = self.get_text_value("跟高FAB")
  437. size_font = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 50)
  438. xiechang_bg = PictureProcessing("RGBA", (top_bg.width, 500), (255, 255, 255,0))
  439. xiechang_bg = xiechang_bg.get_text_image_advanced(
  440. value=(0, 0),
  441. font=size_font,
  442. text=gengao_fab,
  443. align="center",
  444. fill=self.white_bg_color,
  445. spacing=5,
  446. return_mode="min_image",
  447. )
  448. upper_footer_pp.paste_img(top_img=xiechang_bg, value=(20, 60),base='sw')
  449. top_bg.paste_img(top_img=upper_footer_pp, value=(0, 0),base='cc')
  450. detailed_images.append(top_bg)
  451. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  452. def deal_pic_6(self):
  453. detailed_images = []
  454. goods_art_no_list = list(self.data.keys())
  455. top_bg = PictureProcessing(
  456. r"{}\template_7.jpg".format(
  457. self.root
  458. )
  459. )
  460. detailed_images.append(top_bg)
  461. shoesBg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
  462. pp_jpg = self.get_overlay_pic_from_dict(
  463. goods_art_no=goods_art_no_list[0],
  464. color_name="俯视",
  465. bg_color=self.white_bg_color,
  466. )
  467. _, pp_png = self.image_one_pic(return_orign=True,
  468. goods_art_no=goods_art_no_list[0],
  469. name="俯视",
  470. )
  471. pp_png = pp_png.resize(value=(600))
  472. pp_jpg = pp_jpg.resize(value=(600))
  473. hengxian = PictureProcessing(
  474. r"{}\hengxian.png".format(
  475. self.root
  476. )
  477. )
  478. shuxian = PictureProcessing(
  479. r"{}\shuxian.png".format(
  480. self.root
  481. )
  482. )
  483. bbox = pp_png.get_im().getbbox()
  484. cropped_img = pp_png.get_im().crop(bbox)
  485. hengxian = hengxian.resize(value=(cropped_img.width))
  486. shuxian = shuxian.resize(value=(cropped_img.height),base='high')
  487. shoesBg.paste_img(top_img=pp_jpg, value=(0, 0),base='cc')
  488. shoesBg.paste_img(top_img=hengxian, value=(0, 80),base='cs')
  489. shoesBg.paste_img(top_img=shuxian, value=((shoesBg.width/2- pp_png.width/2), 0),base='ec')
  490. xiechang = self.get_text_value("鞋长")
  491. banggao = self.get_text_value("帮高")
  492. gen_gao = self.get_text_value("跟高")
  493. xiezhang_kuan = self.get_text_value("鞋掌宽")
  494. size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30)
  495. xiechang_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  496. xiechang_bg = xiechang_bg.get_text_image_advanced(
  497. value=(0, 0),
  498. font=size_font,
  499. text=xiechang,
  500. align="center",
  501. fill=self.black_bg_color,
  502. spacing=5,
  503. return_mode="min_image",
  504. )
  505. shoesBg.paste_img(top_img=xiechang_bg, value=(0, 50),base='cs')
  506. banggao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  507. banggao_bg = banggao_bg.get_text_image_advanced(
  508. value=(0, 0),
  509. font=size_font,
  510. text=banggao,
  511. align="center",
  512. fill=self.black_bg_color,
  513. spacing=5,
  514. return_mode="min_image",
  515. )
  516. shoesBg.paste_img(top_img=banggao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='en')
  517. gen_gao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  518. gen_gao_bg = gen_gao_bg.get_text_image_advanced(
  519. value=(0, 0),
  520. font=size_font,
  521. text=gen_gao,
  522. align="center",
  523. fill=self.black_bg_color,
  524. spacing=5,
  525. return_mode="min_image",
  526. )
  527. shoesBg.paste_img(top_img=gen_gao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='es')
  528. xiezhang_kuan_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0))
  529. xiezhang_kuan_bg = xiezhang_kuan_bg.get_text_image_advanced(
  530. value=(0, 0),
  531. font=size_font,
  532. text=xiezhang_kuan,
  533. align="center",
  534. fill=self.black_bg_color,
  535. spacing=5,
  536. return_mode="min_image",
  537. )
  538. shoesBg.paste_img(top_img=xiezhang_kuan_bg,value=((shoesBg.width/2- pp_png.width/2), int(shoesBg.height*0.33)),base='nw')
  539. detailed_images.append(shoesBg)
  540. text_bg5 = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  541. detailed_images.append(text_bg5)
  542. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  543. def deal_pic_7(self):
  544. detailed_images = []
  545. top_bg = PictureProcessing(r"{}\template_6.jpg".format(self.root))
  546. attiribute = PictureProcessing("RGB", (top_bg.width, 300), (255, 255, 255))
  547. x_position = top_bg.width*0.15
  548. text_array = [
  549. {"text":"品牌","position":(x_position,50),"default":"小苏",'base':'nw'},
  550. {"text":"货号","position":(x_position,50),"default":"未填写",'base':'en'},
  551. {"text":"鞋面","position":(x_position,120),"default":"未填写",'base':'nw'},
  552. {"text":"内里","position":(x_position,120),"default":"未填写",'base':'en'},
  553. {"text":"鞋垫","position":(x_position,190),"default":"未填写",'base':'nw'},
  554. {"text":"鞋底","position":(x_position,190),"default":"未填写",'base':'en'},
  555. ]
  556. size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 40)
  557. for item in text_array:
  558. text_flag = item["text"]
  559. position = item["position"]
  560. default = item["default"]
  561. base = item["base"]
  562. text_value = self.get_text_value(item["text"])
  563. if not text_value:
  564. text_value = default
  565. gen_gao_bg = PictureProcessing("RGBA", (top_bg.width, 500), (255, 255, 255,0))
  566. gen_gao_bg = gen_gao_bg.get_text_image_advanced(
  567. value=(0, 0),
  568. font=size_font,
  569. text=f"【{text_flag}】:{text_value}",
  570. align="center",
  571. fill=self.black_bg_color,
  572. spacing=5,
  573. return_mode="min_image",
  574. )
  575. attiribute.paste_img(top_img=gen_gao_bg, value=position,base=base)
  576. bottom = PictureProcessing(r"{}\bottom.jpg".format(self.root))
  577. detailed_images.append(attiribute)
  578. detailed_images.append(bottom)
  579. return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
  580. def deal_pic_8(self):
  581. detailed_images = []
  582. top_bg = PictureProcessing(r"{}\template_10.jpg".format(self.root))
  583. detailed_images.append(top_bg)
  584. bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  585. detailed_images.append(bg_bottom)
  586. # ==========添加颜色===================
  587. pp_list_1 = []
  588. font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 25)
  589. goods_art_no_list = list(self.data.keys())
  590. all_color_name = []
  591. for index, goods_art_no in enumerate(goods_art_no_list):
  592. pp_jpg = self.get_overlay_pic_from_dict(
  593. goods_art_no=goods_art_no,
  594. color_name="俯视",
  595. bg_color=self.white_bg_color,
  596. )
  597. if pp_jpg is None:
  598. continue
  599. pp_jpg = pp_jpg.resize(value=440)
  600. color_name = self.goods_no_value["货号资料"][index]["颜色名称"]
  601. all_color_name.append(color_name)
  602. text_bg = PictureProcessing("RGB", (440, 200), self.white_bg_color)
  603. text_bg = text_bg.get_text_image_advanced(
  604. value=(220, 10),
  605. font=font,
  606. text="{}".format(color_name),
  607. align="center",
  608. anchor="mm",
  609. spacing=5,
  610. fill=(55, 55, 55),
  611. return_mode="min_image_high",
  612. margins=(10, 5, 0, 0)
  613. )
  614. # text_bg.show()
  615. _bg = PictureProcessing("RGB", (440, pp_jpg.height + text_bg.height), self.white_bg_color)
  616. _bg = _bg.paste_img(top_img=pp_jpg)
  617. _bg = _bg.paste_img(top_img=text_bg, value=(0, pp_jpg.height))
  618. pp_list_1.append(_bg)
  619. rows = 2
  620. shoes_bg = PictureProcessing().horizontal_distribution(
  621. pp_list=pp_list_1,
  622. bg_width=1200,
  623. margins=(0, 0, 40, 40),
  624. line_spacing=60,
  625. number_per_row=rows,
  626. )
  627. detailed_images.append(shoes_bg)
  628. bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
  629. detailed_images.append(bg_bottom)
  630. return PictureProcessing(im=self.add_pic(detailed_images))
  631. def createReactView(self,_bg,goods_art_no_list,image_name="内里",past_position=(0,0),position_base='cc',rotate=0,resize=0,title="01.经典鞋头 | ",sub_title=""):
  632. radius_react = PictureProcessing("RGB", (_bg.width*0.9, 600), (214, 190, 166))
  633. radius_react = radius_react.radius(circular_pos=(1, 1, 1,1), value=60)
  634. _, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name=image_name)
  635. pp_png =pp_png.crop(mode='min')
  636. pp_png = pp_png.resize(value=round(resize))
  637. pp_png = pp_png.rotate_advance(doge=rotate)
  638. radius_react = radius_react.paste_img(top_img=pp_png, value=past_position,base=position_base)
  639. _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
  640. BottomReact = PictureProcessing("RGB", (_bg.width*0.9, 100), (232, 232, 232))
  641. BottomReact = BottomReact.radius(circular_pos=(0, 0,1, 1), value=60)
  642. size_font_bold = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
  643. size_font = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 50)
  644. xiezhang_kuan_bg = PictureProcessing("RGBA", (BottomReact.width, 500), (255, 255, 255,0))
  645. xiezhang_kuan_bg = xiezhang_kuan_bg.get_text_image_advanced(
  646. value=(0, 0),
  647. font=size_font_bold,
  648. text=title,
  649. align="center",
  650. fill=self.black_bg_color,
  651. spacing=5,
  652. return_mode="min_image",
  653. )
  654. BottomReact =BottomReact.paste_img(top_img=xiezhang_kuan_bg,value=(20,0),base='wc')
  655. font_width = self.get_font_render_size(title, font=size_font_bold)
  656. sub_title_bg = PictureProcessing("RGBA", (BottomReact.width, 500), (255, 255, 255,0))
  657. sub_title_bg = sub_title_bg.get_text_image_advanced(
  658. value=(0, 0),
  659. font=size_font,
  660. text=sub_title,
  661. align="center",
  662. fill=self.black_bg_color,
  663. spacing=5,
  664. return_mode="min_image",
  665. )
  666. BottomReact =BottomReact.paste_img(top_img=sub_title_bg,value=(40+font_width[0],0),base='wc')
  667. _bg = _bg.paste_img(top_img=BottomReact, value=(0, 0),base='cs')
  668. return _bg
  669. def deal_pic_9(self):
  670. detailed_images = []
  671. goods_art_no_list = list(self.data.keys())
  672. top_bg = PictureProcessing(r"{}\template_12.jpg".format(self.root))
  673. detailed_images.append(top_bg)
  674. # 鞋头
  675. _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
  676. _bg = self.createReactView(_bg,
  677. goods_art_no_list,
  678. image_name="内里",
  679. past_position=(_bg.width*0.9*0.3, _bg.height*0.2),
  680. position_base='sw',rotate=-140,resize=round(_bg.width*1.2),title="01.经典鞋头 | ",sub_title="柔软面料上脚舒适")
  681. detailed_images.append(_bg)
  682. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  683. detailed_images.append(line)
  684. # 鞋跟
  685. _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
  686. _bg = self.createReactView(_bg,
  687. goods_art_no_list,
  688. image_name="侧视",
  689. past_position=(-_bg.width*0.9*0.3, _bg.height*0.25),
  690. position_base='cc',rotate=30,resize=round(_bg.width*1.2),title="02.舒适跟脚 | ",sub_title="轻便好穿,久走不累")
  691. detailed_images.append(_bg)
  692. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  693. detailed_images.append(line)
  694. # 鞋底
  695. _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
  696. _bg = self.createReactView(_bg,
  697. goods_art_no_list,
  698. image_name="鞋底",
  699. past_position=(_bg.width*0.9*0.3, _bg.height*0.15),
  700. position_base='sw',rotate=0,resize=round(_bg.width),title="03.缓震鞋底 | ",sub_title="弹性减震,底纹清晰可见")
  701. detailed_images.append(_bg)
  702. line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
  703. detailed_images.append(line)
  704. # 鞋底
  705. return PictureProcessing(im=self.add_pic(detailed_images))
  706. def deal_pic_10(self):
  707. # 模特展示
  708. top_bg = PictureProcessing(r"{}\template_15.jpg".format(self.root))
  709. modelImages = self.extendImages.get("模特图")
  710. detailed_images = []
  711. detailed_images.append(top_bg)
  712. if modelImages:
  713. for modelImage in modelImages:
  714. modelImage = PictureProcessing(modelImage)
  715. modelImage = modelImage.resize(value=round(top_bg.width))
  716. detailed_images.append(modelImage)
  717. return PictureProcessing(im=self.add_pic(detailed_images))
  718. def deal_pic_11(self):
  719. detailed_images = []
  720. detailed_images.append(PictureProcessing(r"{}\template_22.jpg".format(self.root)))
  721. return PictureProcessing(im=self.add_pic(detailed_images))
  722. def get_font_render_size(self, text, font, canvas_size=(2048, 2048)):
  723. canvas = Image.new('RGB', canvas_size)
  724. draw = ImageDraw.Draw(canvas)
  725. draw.text((0, 0), text, font=font, fill=(55, 55, 55))
  726. bbox = canvas.getbbox()
  727. # 宽高
  728. size = (bbox[2] - bbox[0], bbox[3] - bbox[1])
  729. return size