from PIL import Image, ImageDraw, ImageFont import os def generate_ppt_image(analyzed_text): # 创建一个空白图像 img = Image.new('RGB', (1920, 1080), color='white') d = ImageDraw.Draw(img) # 加载字体 title_font = ImageFont.truetype("霞鹜文楷.ttf", 60) subtitle_font = ImageFont.truetype("霞鹜文楷.ttf", 40) body_font = ImageFont.truetype("霞鹜文楷.ttf", 30) # 绘制标题 d.text((100, 100), analyzed_text['title'], fill=(0,0,0), font=title_font) # 绘制副标题 d.text((100, 200), analyzed_text['subtitle'], fill=(100,100,100), font=subtitle_font) # 绘制要点 y_position = 300 for point in analyzed_text['key_points']: d.text((100, y_position), f"• {point}", fill=(0,0,0), font=body_font) y_position += 50 # 保存图像 if not os.path.exists('generated'): os.makedirs('generated') image_path = f"generated/ppt_{analyzed_text['title'].replace(' ', '_')}.png" img.save(image_path) return image_path