detail_xiaosushuoxie7.py 35 KB

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