detail_xiaosushuoxie7.py 34 KB

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