""" 步骤: 1、整理需要处理的款号图-输出款号图文件夹 2、整理所有相关的图片作为素材图 3、按要求进行拼接 """ import os import re import settings from PIL import ImageFont # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase # from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing try: is_test_plugins = settings.is_test_plugins except: is_test_plugins = False if is_test_plugins: from custom_plugins.plugins_mode.detail_generate_base import DetailBase from custom_plugins.plugins_mode.pic_deal import PictureProcessing else: from plugins_mode.detail_generate_base import DetailBase from plugins_mode.pic_deal import PictureProcessing from PIL import Image, ImageDraw plugins_name = "详情模板" company_name_list = ["小苏"] template_name = "xiaosushuoxie-7" class DetailPicGet(DetailBase): need_view = ["俯视", "侧视", "后跟", "鞋底", "内里"] root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd()) def __init__(self, goods_no, goods_no_value: dict, out_put_dir, windows=None, test=False,excel_data=None,assigned_page_list=None): super().__init__(goods_no, goods_no_value, out_put_dir, windows=windows,excel_data=excel_data,assigned_page_list=assigned_page_list) self.root = r"{}\resources\detail_temp\xiaosushuoxie\7".format(os.getcwd()) self.template_name = template_name 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, self.deal_pic_3, self.deal_pic_4, self.deal_pic_5, self.deal_pic_6, self.deal_pic_7, self.deal_pic_8, self.deal_pic_9, self.deal_pic_10, self.deal_pic_11, ] if test: 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 == '模特图': # 没有数字的默认为第1张 collected_images['模特图'].append(file_path) elif 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()) detailed_images.append(self.deal_pic_2()) detailed_images.append(self.deal_pic_3()) detailed_images.append(self.deal_pic_4()) detailed_images.append(self.deal_pic_5()) detailed_images.append(self.deal_pic_6()) detailed_images.append(self.deal_pic_7()) detailed_images.append(self.deal_pic_8()) detailed_images.append(self.deal_pic_9()) detailed_images.append(self.deal_pic_10()) detailed_images.append(self.deal_pic_11()) img = self.add_pic(detailed_images) img.save(r"{}/{}.jpg".format(self.out_put_dir,self.goods_no, format="JPEG")) 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("封面标题") if not mainTitle: mainTitle = "未填写" subTitle = self.get_text_value("封面副标题") if not subTitle: subTitle = "未填写" signTitle = self.get_text_value("封面签名") if not signTitle: signTitle = "未填写" fontMain = ImageFont.truetype(r"resources\ttf\DOUYINSANSBOLD.ttf", 200) fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 40) fontSign = ImageFont.truetype(r"resources\ttf\puhui\en\Bold.otf", 40) main_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0)) main_text_bg = main_text_bg.get_text_image_advanced( value=(0, 0), font=fontMain, text=mainTitle, align="center", fill=self.white_bg_color, spacing=5, return_mode="min_image", ) # 副标题 sub_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0)) sub_text_bg = sub_text_bg.get_text_image_advanced( value=(0, 0), font=fontSub, text=subTitle, align="center", fill=self.white_bg_color, spacing=5, return_mode="min_image", ) # 签名 sign_text_bg = PictureProcessing("RGBA", (pp_bg.width, 500), (255, 255, 255,0)) sign_text_bg = sign_text_bg.get_text_image_advanced( value=(0, 0), font=fontSign, text=signTitle, align="center", fill=self.white_bg_color, spacing=5, return_mode="min_image", ) pp_bg = pp_bg.paste_img(top_img=main_text_bg,value=(0,208),base='nc') pp_bg = pp_bg.paste_img(top_img=sub_text_bg,value=(0,470),base='nc') pp_bg = pp_bg.paste_img(top_img=sign_text_bg,value=(0,57),base='nc') bottom_bg = PictureProcessing( r"{}\bolang.png".format( self.root ) ) # pp_bg.paste_img(top_img=bottom_bg, value=(0, 0),base='cs') 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='nc') cover_image_pp.paste_img(top_img=bottom_bg, value=(0, -40),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): """ 细节解析 """ # 文字排列 detailed_images = [] top_bg = PictureProcessing( r"{}\bolang.png".format( self.root ) ) temp_pp = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) detailed_images.append(temp_pp) designText1 = self.get_text_value("设计理念1") if not designText1: designText1 = "未填写" designText2 = self.get_text_value("设计理念2") if not designText2: designText2 = "未填写" designText3 = self.get_text_value("设计理念3") if not designText3: designText3 = "未填写" fontSub = ImageFont.truetype(r"resources\ttf\puhui\Regular.ttf", 60) centerDesign = ImageFont.truetype(r"resources\ttf\puhui\Bold.ttf", 65) first_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) first_text_bg = first_text_bg.get_text_image_advanced( value=(0, 0), font=fontSub, text=designText1, align="center", fill=self.black_bg_color, return_mode="min_image", ) temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) temp_text_bg = temp_text_bg.paste_img(top_img=first_text_bg,value=(0,0),base='cc') detailed_images.append(temp_text_bg) second_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) second_text_bg = second_text_bg.get_text_image_advanced( value=(0, 0), font=centerDesign, text=designText2, align="center", fill=self.black_bg_color, return_mode="min_image", ) temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) temp_text_bg = temp_text_bg.paste_img(top_img=second_text_bg,value=(0,0),base='cc') detailed_images.append(temp_text_bg) third_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) third_text_bg = third_text_bg.get_text_image_advanced( value=(0, 0), font=fontSub, text=designText3, align="center", fill=self.black_bg_color, return_mode="min_image", ) temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) temp_text_bg = temp_text_bg.paste_img(top_img=third_text_bg,value=(0,0),base='cc') detailed_images.append(temp_text_bg) temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) detailed_images.append(temp_text_bg) # 卡片 pp_list_1 = [] font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60) fontEN = ImageFont.truetype(r"resources\ttf\puhui\en\Medium.otf", 30) goods_art_no_list = list(self.data.keys()) pp_jpg = self.get_overlay_pic_from_dict( goods_art_no=goods_art_no_list[0], color_name="俯视", bg_color=self.white_bg_color, ) pp_jpg = pp_jpg.resize(value=840) text_array = [{"title":self.get_text_value("鞋跟描述") ,"bottom":"Comfortable heel","position":(-200, 0)}, {"title":self.get_text_value("鞋头描述"), "position":(200, 0),"bottom":"Versatile Upper"}] for index, item in enumerate(text_array): text_bg = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0)) text_title = item["title"] if not text_title: text_title = "未填写" text_bg = text_bg.get_text_image_advanced( value=(0, 0), font=font, text="{}".format(text_title), align="center", spacing=15, fill=(255, 255, 255), return_mode="min_image", margins=(10, 5, 0, 0), max_len_one_line=6 ) _bg = PictureProcessing("RGB", (520, 880), (208, 186, 162)) _bg = _bg.radius(circular_pos=(1, 1, 1, 1), value=60) _bg = _bg.paste_img(top_img=text_bg, value=(0, 50),base='nc') text_bottome = PictureProcessing("RGBA", (440, 200), (255, 255, 255,0)) text_bottome = text_bottome.get_text_image_advanced( value=(0, 0), font=fontEN, text="{}".format(item["bottom"]), align="center", spacing=15, fill=(255, 255, 255), return_mode="min_image", margins=(10, 5, 0, 0), ) _bg = _bg.paste_img(top_img=text_bottome, value=(0, 50),base='cs') # 第一张图 first_imageBg = PictureProcessing("RGB", (420, 600), self.white_bg_color) first_imageBg.paste_img(top_img=pp_jpg, value=item["position"], base='cc') _bg = _bg.paste_img(top_img=first_imageBg, value=(0, 0),base='cc') pp_list_1.append(_bg) rows = 2 shoes_bg = PictureProcessing().horizontal_distribution( pp_list=pp_list_1, bg_width=top_bg.width, margins=(0, 0, 50, 50), line_spacing=60, number_per_row=rows, ) detailed_images.append(shoes_bg) temp_text_bg = PictureProcessing("RGB", (top_bg.width, 90), self.white_bg_color) detailed_images.append(temp_text_bg) return PictureProcessing(im=self.add_pic(detailed_images)) def deal_pic_3(self): detailed_images = [] pp_bg = PictureProcessing( r"{}\template_4.jpg".format( self.root ) ) 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) text_bg = PictureProcessing("RGB", (440, 200), (255, 255, 255)) text1 = self.get_text_value("面料FAB1") if not text1: text1 = "轻盈透气" text_bg = text_bg.get_text_image_advanced( value=(0, 0), font=font1, text=text1, align="left", spacing=5, fill=(194, 189, 167), return_mode="min_image", ) _bg.paste_img(top_img=text_bg, value=(50, 40),base='nw') # text2 text2 = self.get_text_value("面料FAB2") if not text2: text2 = "(软弹不易累脚)" text_bg2 = PictureProcessing("RGB", (440, 200), (255, 255, 255)) text_bg2 = text_bg2.get_text_image_advanced( value=(0, 0), font=font2, text=text2, align="left", spacing=5, fill=(194, 189, 167), return_mode="min_image", ) _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)) def deal_pic_4(self): # =============设计理念================ detail_images = [] top_bg = PictureProcessing(r"{}\template_5.jpg".format(self.root)) goods_art_no_list = list(self.data.keys()) 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)) # textTitle1 = self.get_text_value("材质FAB1") if not textTitle1: textTitle1 = "未填写" textTitle2 = self.get_text_value("材质FAB2") if not textTitle2: textTitle2 = "未填写" font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 100) font2 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 60) font3 = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 50) titleBg = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255)) titleBg = titleBg.get_text_image_advanced( value=(0, 0), font=font, text=textTitle1, align="left", spacing=5, fill=(53, 49, 48), return_mode="min_image", ) top_bg.paste_img(top_img=titleBg, value=(0, 100),base='nc') text_bg2 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255)) text_bg2 = titleBg.get_text_image_advanced( value=(0, 0), font=font2, text=textTitle2, align="left", spacing=5, fill=(53, 49, 48), return_mode="min_image", ) top_bg.paste_img(top_img=text_bg2, value=(0, 230),base='nc') textTitle3 = self.get_text_value("材质FAB3") if not textTitle3: textTitle3 = "未填写" text_bg3 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255)) text_bg3 = text_bg3.get_text_image_advanced( value=(0, 0), font=font3, text=textTitle3, align="center", spacing=5, fill=(53, 49, 48), return_mode="min_image", max_len_one_line=4 ) top_bg.paste_img(top_img=text_bg3, value=(154, 1325),base='nw') textTitle4 = self.get_text_value("材质FAB4") if not textTitle4: textTitle4 = "未填写" text_bg4 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255)) text_bg4 = text_bg4.get_text_image_advanced( value=(0, 0), font=font3, text=textTitle4, align="center", spacing=5, fill=(53, 49, 48), return_mode="min_image", max_len_one_line=4 ) top_bg.paste_img(top_img=text_bg4, value=(0, 1325),base='nc') textTitle5 = self.get_text_value("材质FAB5") if not textTitle5: textTitle5 = "未填写" text_bg5 = PictureProcessing("RGB", (top_bg.width, 200), (255, 255, 255)) text_bg5 = text_bg5.get_text_image_advanced( value=(0, 0), font=font3, text=textTitle5, align="center", spacing=5, fill=(53, 49, 48), return_mode="min_image", max_len_one_line=4 ) top_bg.paste_img(top_img=text_bg5, value=(154, 1325),base='en') detail_images.append(top_bg) return PictureProcessing(im=self.add_pic(detail_images)) def deal_pic_5(self): detailed_images = [] 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(1100),base='high') gengao_fab = self.get_text_value("跟高FAB") if not gengao_fab: gengao_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): detailed_images = [] goods_art_no_list = list(self.data.keys()) top_bg = PictureProcessing( r"{}\template_7.jpg".format( self.root ) ) detailed_images.append(top_bg) shoesBg = PictureProcessing("RGB", (top_bg.width, 600), self.white_bg_color) pp_jpg = self.get_overlay_pic_from_dict( goods_art_no=goods_art_no_list[0], color_name="俯视", bg_color=self.white_bg_color, ) _, pp_png = self.image_one_pic(return_orign=True, goods_art_no=goods_art_no_list[0], name="俯视", ) pp_png = pp_png.resize(value=(600)) pp_jpg = pp_jpg.resize(value=(600)) hengxian = PictureProcessing( r"{}\hengxian.png".format( self.root ) ) shuxian = PictureProcessing( r"{}\shuxian.png".format( self.root ) ) bbox = pp_png.get_im().getbbox() cropped_img = pp_png.get_im().crop(bbox) hengxian = hengxian.resize(value=(cropped_img.width)) shuxian = shuxian.resize(value=(cropped_img.height),base='high') shoesBg.paste_img(top_img=pp_jpg, value=(0, 0),base='cc') shoesBg.paste_img(top_img=hengxian, value=(0, 80),base='cs') shoesBg.paste_img(top_img=shuxian, value=((shoesBg.width/2- pp_png.width/2), 0),base='ec') xiechang = self.get_text_value("鞋长") if not xiechang: xiechang = "未填写" banggao = self.get_text_value("帮高") if not banggao: banggao = "未填写" gen_gao = self.get_text_value("跟高") if not gen_gao: gen_gao = "未填写" xiezhang_kuan = self.get_text_value("鞋掌宽") if not xiezhang_kuan: xiezhang_kuan = "未填写" size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 30) xiechang_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0)) xiechang_bg = xiechang_bg.get_text_image_advanced( value=(0, 0), font=size_font, text=xiechang, align="center", fill=self.black_bg_color, spacing=5, return_mode="min_image", ) shoesBg.paste_img(top_img=xiechang_bg, value=(0, 50),base='cs') banggao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0)) banggao_bg = banggao_bg.get_text_image_advanced( value=(0, 0), font=size_font, text=banggao, align="center", fill=self.black_bg_color, spacing=5, return_mode="min_image", ) shoesBg.paste_img(top_img=banggao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='en') gen_gao_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0)) gen_gao_bg = gen_gao_bg.get_text_image_advanced( value=(0, 0), font=size_font, text=gen_gao, align="center", fill=self.black_bg_color, spacing=5, return_mode="min_image", ) shoesBg.paste_img(top_img=gen_gao_bg,value=((shoesBg.width/2- pp_png.width/2)-140, int(shoesBg.height*0.33)),base='es') xiezhang_kuan_bg = PictureProcessing("RGBA", (shoesBg.width, 500), (255, 255, 255,0)) xiezhang_kuan_bg = xiezhang_kuan_bg.get_text_image_advanced( value=(0, 0), font=size_font, text=xiezhang_kuan, align="center", fill=self.black_bg_color, spacing=5, return_mode="min_image", ) shoesBg.paste_img(top_img=xiezhang_kuan_bg,value=((shoesBg.width/2- pp_png.width/2), int(shoesBg.height*0.33)),base='nw') detailed_images.append(shoesBg) text_bg5 = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255)) detailed_images.append(text_bg5) return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images))) def deal_pic_7(self): detailed_images = [] top_bg = PictureProcessing(r"{}\template_6.jpg".format(self.root)) attiribute = PictureProcessing("RGB", (top_bg.width, 300), (255, 255, 255)) x_position = top_bg.width*0.15 text_array = [ {"text":"品牌","position":(x_position,50),"default":"小苏",'base':'nw'}, {"text":"货号","position":(740,50),"default":"未填写",'base':'nw'}, {"text":"鞋面","position":(x_position,120),"default":"未填写",'base':'nw'}, {"text":"内里","position":(740,120),"default":"未填写",'base':'nw'}, {"text":"鞋垫","position":(x_position,190),"default":"未填写",'base':'nw'}, {"text":"鞋底","position":(740,190),"default":"未填写",'base':'nw'}, ] size_font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 35) for item in text_array: text_flag = item["text"] position = item["position"] default = item["default"] base = item["base"] text_value = self.get_text_value(item["text"]) if not text_value: text_value = default gen_gao_bg = PictureProcessing("RGBA", (top_bg.width, 500), (255, 255, 255,0)) gen_gao_bg = gen_gao_bg.get_text_image_advanced( value=(0, 0), font=size_font, text=f"【{text_flag}】:{text_value}", align="center", fill=self.black_bg_color, spacing=5, return_mode="min_image", max_len_one_line=15 ) attiribute.paste_img(top_img=gen_gao_bg, value=position,base=base) bottom = PictureProcessing(r"{}\bottom.jpg".format(self.root)) detailed_images.append(attiribute) detailed_images.append(bottom) return self.pp_pic_subsection(PictureProcessing(im=self.add_pic(detailed_images))) def deal_pic_8(self): detailed_images = [] top_bg = PictureProcessing(r"{}\template_10.jpg".format(self.root)) detailed_images.append(top_bg) bg_bottom = PictureProcessing("RGB", (top_bg.width, 100), (255, 255, 255)) detailed_images.append(bg_bottom) # ==========添加颜色=================== pp_list_1 = [] font = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 35) goods_art_no_list = list(self.data.keys()) all_color_name = [] for index, goods_art_no in enumerate(goods_art_no_list): pp_jpg = self.get_overlay_pic_from_dict( goods_art_no=goods_art_no, color_name="俯视", bg_color=self.white_bg_color, ) if pp_jpg is None: continue pp_jpg = pp_jpg.resize(value=440) color_name = self.goods_no_value["货号资料"][index]["颜色名称"] all_color_name.append(color_name) text_bg = PictureProcessing("RGB", (440, 200), self.white_bg_color) text_bg = text_bg.get_text_image_advanced( value=(220, 10), font=font, text="{}".format(color_name), align="center", anchor="mm", spacing=5, fill=(55, 55, 55), return_mode="min_image_high", margins=(10, 5, 0, 0) ) # text_bg.show() _bg = PictureProcessing("RGB", (440, pp_jpg.height + text_bg.height), self.white_bg_color) _bg = _bg.paste_img(top_img=pp_jpg) _bg = _bg.paste_img(top_img=text_bg, value=(0, pp_jpg.height)) pp_list_1.append(_bg) rows = 2 shoes_bg = PictureProcessing().horizontal_distribution( pp_list=pp_list_1, bg_width=1200, margins=(0, 0, 40, 40), line_spacing=60, number_per_row=rows, ) detailed_images.append(shoes_bg) 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("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("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("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): # 模特展示 top_bg = PictureProcessing(r"{}\template_15.jpg".format(self.root)) modelImages = self.extendImages.get("模特图") detailed_images = [] detailed_images.append(top_bg) if modelImages: for index, modelImage in enumerate(modelImages): itemIndex = index + 1 modelImage = PictureProcessing(modelImage) if itemIndex % 2 == 0: modelImage = modelImage.resize(value=round(top_bg.width*0.9)) else: modelImage = modelImage.resize(value=round(top_bg.width)) _bg = PictureProcessing("RGBA", (top_bg.width, modelImage.height), (255, 255, 255,0)) _bg = _bg.paste_img(top_img=modelImage, value=(0, 0),base='cc') detailed_images.append(_bg) return PictureProcessing(im=self.add_pic(detailed_images)) def deal_pic_11(self): detailed_images = [] detailed_images.append(PictureProcessing(r"{}\template_22.jpg".format(self.root))) return PictureProcessing(im=self.add_pic(detailed_images)) def get_font_render_size(self, text, font, canvas_size=(2048, 2048)): canvas = Image.new('RGB', canvas_size) draw = ImageDraw.Draw(canvas) draw.text((0, 0), text, font=font, fill=(55, 55, 55)) bbox = canvas.getbbox() # 宽高 size = (bbox[2] - bbox[0], bbox[3] - bbox[1]) return size