|
|
@@ -5,6 +5,7 @@
|
|
|
3、按要求进行拼接
|
|
|
"""
|
|
|
import os
|
|
|
+import re
|
|
|
import settings
|
|
|
|
|
|
from PIL import ImageFont
|
|
|
@@ -40,6 +41,7 @@ class DetailPicGet(DetailBase):
|
|
|
self.base_bg_color = (236, 226, 211)
|
|
|
self.white_bg_color = (255, 255, 255)
|
|
|
self.black_bg_color = (0, 0, 0)
|
|
|
+ self.getExtendImages()
|
|
|
self.deal_pic_func_list = [
|
|
|
self.deal_pic_1,
|
|
|
self.deal_pic_2,
|
|
|
@@ -58,8 +60,61 @@ class DetailPicGet(DetailBase):
|
|
|
self.run_test()
|
|
|
else:
|
|
|
self.run_all()
|
|
|
-
|
|
|
-
|
|
|
+ def collect_images_by_rules(self,directory_path):
|
|
|
+ """
|
|
|
+ 根据规则收集图片:
|
|
|
+ - '封面图' 和 '上脚图' 各只取一张(如果有多张则取第一张)
|
|
|
+ - '模特图' 可能有多张(包括模特图、模特图2、模特图3等)
|
|
|
+ """
|
|
|
+ collected_images = {
|
|
|
+ '封面图': None,
|
|
|
+ '上脚图': None,
|
|
|
+ '场景图': None,
|
|
|
+ '模特图': [] # 存储所有模特图
|
|
|
+ }
|
|
|
+
|
|
|
+ for filename in os.listdir(directory_path):
|
|
|
+ file_path = os.path.join(directory_path, filename)
|
|
|
+
|
|
|
+ if os.path.isfile(file_path):
|
|
|
+ name_part, ext = os.path.splitext(filename)
|
|
|
+
|
|
|
+ if ext.lower() in ['.jpg', '.jpeg', '.png', '.gif', '.bmp']:
|
|
|
+ # 处理封面图
|
|
|
+ if name_part == '封面图' and collected_images['封面图'] is None:
|
|
|
+ collected_images['封面图'] = file_path
|
|
|
+
|
|
|
+ # 处理上脚图
|
|
|
+ elif name_part == '上脚图' and collected_images['上脚图'] is None:
|
|
|
+ collected_images['上脚图'] = file_path
|
|
|
+
|
|
|
+ # 处理场景图
|
|
|
+ elif name_part == '场景图' and collected_images['场景图'] is None:
|
|
|
+ collected_images['场景图'] = file_path
|
|
|
+
|
|
|
+ # 处理模特图(包括模特图、模特图2、模特图3等)
|
|
|
+ elif name_part.startswith('模特图'):
|
|
|
+ # 验证是否是模特图的正确格式(模特图 或 模特图+数字)
|
|
|
+ if name_part == '模特图' or re.match(r'^模特图\d+$', name_part):
|
|
|
+ collected_images['模特图'].append(file_path)
|
|
|
+
|
|
|
+ return collected_images
|
|
|
+ def getExtendImages(self):
|
|
|
+ # 增加逻辑,获取任意货号下的组合图
|
|
|
+ self.extendImages = {}
|
|
|
+ goods_art_no_list = list(self.data.keys())
|
|
|
+ for goods_art_no in goods_art_no_list:
|
|
|
+ _, path = next(iter(self.data[goods_art_no]["pics"].items()))
|
|
|
+ parent_path = os.path.dirname(os.path.dirname(path))
|
|
|
+ new_dir = "拓展"
|
|
|
+ extends_path = os.path.join(parent_path, new_dir)
|
|
|
+ if not os.path.isdir(extends_path):
|
|
|
+ continue
|
|
|
+ images = self.collect_images_by_rules(extends_path)
|
|
|
+ if self.extendImages:
|
|
|
+ continue
|
|
|
+ self.extendImages = images
|
|
|
+ print("self.extendImages",self.extendImages)
|
|
|
def run_test(self):
|
|
|
detailed_images = []
|
|
|
detailed_images.append(self.deal_pic_1())
|
|
|
@@ -79,6 +134,7 @@ class DetailPicGet(DetailBase):
|
|
|
def deal_pic_1(self):
|
|
|
""" 制作主图 """
|
|
|
detailed_images = []
|
|
|
+ cover_image = self.extendImages.get("封面图")
|
|
|
pp_bg = PictureProcessing(r"{}\first_bg.png".format(self.root))
|
|
|
# -------粘贴文字-------
|
|
|
mainTitle = self.get_text_value("主标题")
|
|
|
@@ -128,7 +184,14 @@ class DetailPicGet(DetailBase):
|
|
|
)
|
|
|
)
|
|
|
pp_bg.paste_img(top_img=bottom_bg, value=(0, 0),base='cs')
|
|
|
- detailed_images.append(pp_bg)
|
|
|
+ if cover_image:
|
|
|
+ cover_image_pp = PictureProcessing(cover_image)
|
|
|
+ cover_image_pp = cover_image_pp.resize(value=(pp_bg.width))
|
|
|
+ pp_bg = pp_bg.resize(value=(cover_image_pp.height),base='high')
|
|
|
+ cover_image_pp.paste_img(top_img=pp_bg, value=(0, 0),base='cs')
|
|
|
+ detailed_images.append(cover_image_pp)
|
|
|
+ else:
|
|
|
+ detailed_images.append(pp_bg)
|
|
|
return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
|
|
|
def deal_pic_2(self):
|
|
|
@@ -254,7 +317,8 @@ class DetailPicGet(DetailBase):
|
|
|
self.root
|
|
|
)
|
|
|
)
|
|
|
- _bg = PictureProcessing("RGB", (pp_bg.width*0.8, pp_bg.height*0.8), self.white_bg_color)
|
|
|
+ scene_image = self.extendImages.get("场景图")
|
|
|
+ _bg = PictureProcessing("RGB", (pp_bg.width*0.8, pp_bg.height*0.86), self.white_bg_color)
|
|
|
_bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60)
|
|
|
font1 = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 100)
|
|
|
font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50)
|
|
|
@@ -286,7 +350,12 @@ class DetailPicGet(DetailBase):
|
|
|
fill=(194, 189, 167),
|
|
|
return_mode="min_image",
|
|
|
)
|
|
|
- _bg.paste_img(top_img=text_bg2, value=(50, 140),base='en')
|
|
|
+ _bg.paste_img(top_img=text_bg2, value=(50, 120),base='en')
|
|
|
+ # scene_image
|
|
|
+ if scene_image:
|
|
|
+ scene_image_pp = PictureProcessing(scene_image)
|
|
|
+ scene_image_pp = scene_image_pp.resize(value=round(_bg.width*0.85))
|
|
|
+ _bg.paste_img(top_img=scene_image_pp, value=(0, _bg.height*0.05),base='cs')
|
|
|
pp_bg = pp_bg.paste_img(top_img=_bg, value=(0, 0),base='cc')
|
|
|
detailed_images.append(pp_bg)
|
|
|
return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
@@ -373,12 +442,29 @@ class DetailPicGet(DetailBase):
|
|
|
return PictureProcessing(im=self.add_pic(detail_images))
|
|
|
def deal_pic_5(self):
|
|
|
detailed_images = []
|
|
|
- goods_art_no_list = list(self.data.keys())
|
|
|
top_bg = PictureProcessing(
|
|
|
r"{}\template_6.jpg".format(
|
|
|
self.root
|
|
|
)
|
|
|
)
|
|
|
+ upper_footer_image = self.extendImages.get("上脚图")
|
|
|
+ if upper_footer_image:
|
|
|
+ upper_footer_pp = PictureProcessing(upper_footer_image)
|
|
|
+ upper_footer_pp = upper_footer_pp.resize(value=round(top_bg.height*0.9),base='high')
|
|
|
+ gengao_fab = self.get_text_value("跟高FAB")
|
|
|
+ size_font = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 50)
|
|
|
+ xiechang_bg = PictureProcessing("RGBA", (top_bg.width, 500), (255, 255, 255,0))
|
|
|
+ xiechang_bg = xiechang_bg.get_text_image_advanced(
|
|
|
+ value=(0, 0),
|
|
|
+ font=size_font,
|
|
|
+ text=gengao_fab,
|
|
|
+ align="center",
|
|
|
+ fill=self.white_bg_color,
|
|
|
+ spacing=5,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ upper_footer_pp.paste_img(top_img=xiechang_bg, value=(20, 60),base='sw')
|
|
|
+ top_bg.paste_img(top_img=upper_footer_pp, value=(0, 0),base='cc')
|
|
|
detailed_images.append(top_bg)
|
|
|
return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images)))
|
|
|
def deal_pic_6(self):
|
|
|
@@ -569,51 +655,93 @@ class DetailPicGet(DetailBase):
|
|
|
bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255))
|
|
|
detailed_images.append(bg_bottom)
|
|
|
return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
+
|
|
|
+ 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=""):
|
|
|
+ radius_react = PictureProcessing("RGB", (_bg.width*0.9, 600), (214, 190, 166))
|
|
|
+ radius_react = radius_react.radius(circular_pos=(1, 1, 1,1), value=60)
|
|
|
+ _, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name=image_name)
|
|
|
+ pp_png =pp_png.crop(mode='min')
|
|
|
+ pp_png = pp_png.resize(value=round(resize))
|
|
|
+ pp_png = pp_png.rotate_advance(doge=rotate)
|
|
|
+ radius_react = radius_react.paste_img(top_img=pp_png, value=past_position,base=position_base)
|
|
|
+ _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
|
|
|
+ BottomReact = PictureProcessing("RGB", (_bg.width*0.9, 100), (232, 232, 232))
|
|
|
+ BottomReact = BottomReact.radius(circular_pos=(0, 0,1, 1), value=60)
|
|
|
+ size_font_bold = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 60)
|
|
|
+ size_font = ImageFont.truetype(r"resources\ttf\puhui\Light.ttf", 50)
|
|
|
+ xiezhang_kuan_bg = PictureProcessing("RGBA", (BottomReact.width, 500), (255, 255, 255,0))
|
|
|
+ xiezhang_kuan_bg = xiezhang_kuan_bg.get_text_image_advanced(
|
|
|
+ value=(0, 0),
|
|
|
+ font=size_font_bold,
|
|
|
+ text=title,
|
|
|
+ align="center",
|
|
|
+ fill=self.black_bg_color,
|
|
|
+ spacing=5,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ BottomReact =BottomReact.paste_img(top_img=xiezhang_kuan_bg,value=(20,0),base='wc')
|
|
|
+ font_width = self.get_font_render_size(title, font=size_font_bold)
|
|
|
+ sub_title_bg = PictureProcessing("RGBA", (BottomReact.width, 500), (255, 255, 255,0))
|
|
|
+ sub_title_bg = sub_title_bg.get_text_image_advanced(
|
|
|
+ value=(0, 0),
|
|
|
+ font=size_font,
|
|
|
+ text=sub_title,
|
|
|
+ align="center",
|
|
|
+ fill=self.black_bg_color,
|
|
|
+ spacing=5,
|
|
|
+ return_mode="min_image",
|
|
|
+ )
|
|
|
+ BottomReact =BottomReact.paste_img(top_img=sub_title_bg,value=(40+font_width[0],0),base='wc')
|
|
|
+ _bg = _bg.paste_img(top_img=BottomReact, value=(0, 0),base='cs')
|
|
|
+ return _bg
|
|
|
def deal_pic_9(self):
|
|
|
detailed_images = []
|
|
|
goods_art_no_list = list(self.data.keys())
|
|
|
top_bg = PictureProcessing(r"{}\template_12.jpg".format(self.root))
|
|
|
detailed_images.append(top_bg)
|
|
|
# 鞋头
|
|
|
- _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
|
|
|
- radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
|
|
|
- radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
|
|
|
- _, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name="内里")
|
|
|
- pp_png = pp_png.resize(value=round(top_bg.width*1.5))
|
|
|
- pp_png = pp_png.rotate(doge=-120)
|
|
|
- # _bg = _bg.paste_img(top_img=pp_png, value=(0, 0),base='cc')
|
|
|
- radius_react.paste_img(top_img=pp_png, value=(0, 0),base='cc')
|
|
|
- detailed_images.append(radius_react)
|
|
|
+ _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
|
|
|
+ _bg = self.createReactView(_bg,
|
|
|
+ goods_art_no_list,
|
|
|
+ image_name="内里",
|
|
|
+ past_position=(_bg.width*0.9*0.3, _bg.height*0.2),
|
|
|
+ position_base='sw',rotate=-140,resize=round(_bg.width*1.2),title="01.经典鞋头 | ",sub_title="柔软面料上脚舒适")
|
|
|
+ detailed_images.append(_bg)
|
|
|
line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
|
|
|
detailed_images.append(line)
|
|
|
# 鞋跟
|
|
|
- _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
|
|
|
- radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
|
|
|
- radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
|
|
|
- _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
|
|
|
+ _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
|
|
|
+ _bg = self.createReactView(_bg,
|
|
|
+ goods_art_no_list,
|
|
|
+ image_name="侧视",
|
|
|
+ past_position=(-_bg.width*0.9*0.3, _bg.height*0.25),
|
|
|
+ position_base='cc',rotate=30,resize=round(_bg.width*1.2),title="02.舒适跟脚 | ",sub_title="轻便好穿,久走不累")
|
|
|
detailed_images.append(_bg)
|
|
|
line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
|
|
|
detailed_images.append(line)
|
|
|
# 鞋底
|
|
|
- _bg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color)
|
|
|
- radius_react = PictureProcessing("RGB", (top_bg.width*0.9, 600), (214, 190, 166))
|
|
|
- radius_react = radius_react.radius(circular_pos=(1, 1, 1, 1), value=60)
|
|
|
- _bg = _bg.paste_img(top_img=radius_react, value=(0, 0),base='cc')
|
|
|
- pp_jpg, pp_png = self.image_one_pic(return_orign=True,goods_art_no=goods_art_no_list[0],name="俯视")
|
|
|
- pp_jpg = pp_jpg.resize(value=round(top_bg.width*0.8))
|
|
|
- pp_png = pp_png.resize(value=round(top_bg.width*0.8))
|
|
|
- top_bg = top_bg.to_overlay_pic_advance(top_img=pp_jpg, top_png_img=pp_png, base="cc",value=(0, 0))
|
|
|
+ _bg = PictureProcessing("RGBA", (top_bg.width, 600), (255, 255, 255,0))
|
|
|
+ _bg = self.createReactView(_bg,
|
|
|
+ goods_art_no_list,
|
|
|
+ image_name="鞋底",
|
|
|
+ past_position=(_bg.width*0.9*0.3, _bg.height*0.15),
|
|
|
+ position_base='sw',rotate=0,resize=round(_bg.width),title="03.缓震鞋底 | ",sub_title="弹性减震,底纹清晰可见")
|
|
|
detailed_images.append(_bg)
|
|
|
line = PictureProcessing("RGB", (top_bg.width, 100), self.white_bg_color)
|
|
|
detailed_images.append(line)
|
|
|
# 鞋底
|
|
|
return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
def deal_pic_10(self):
|
|
|
- # template_15.jpg
|
|
|
# 模特展示
|
|
|
top_bg = PictureProcessing(r"{}\template_15.jpg".format(self.root))
|
|
|
+ modelImages = self.extendImages.get("模特图")
|
|
|
detailed_images = []
|
|
|
detailed_images.append(top_bg)
|
|
|
+ if modelImages:
|
|
|
+ for modelImage in modelImages:
|
|
|
+ modelImage = PictureProcessing(modelImage)
|
|
|
+ modelImage = modelImage.resize(value=round(top_bg.width))
|
|
|
+ detailed_images.append(modelImage)
|
|
|
return PictureProcessing(im=self.add_pic(detailed_images))
|
|
|
def deal_pic_11(self):
|
|
|
detailed_images = []
|