from PIL import Image, ImageDraw, ImageFont def create_wanted_poster(): # 1. 基础画布设置 (暗色调营造压迫感) width, height = 800, 1000 bg_color = (15, 15, 15) # 极暗的背景色 border_color = (139, 0, 0) # 暗红色边框 text_color = (220, 220, 220) # 灰白色文字 accent_color = (180, 20, 20) # 强调色(暗红) # 创建画布和绘图对象 img = Image.new('RGB', (width, height), bg_color) draw = ImageDraw.Draw(img) # 绘制带有压迫感的粗边框 border_width = 20 draw.rectangle([0, 0, width-1, height-1], outline=border_color, width=border_width) draw.rectangle([30, 30, width-30, height-30], outline=border_color, width=5) # 2. 字体设置 (尽量使用系统自带的粗体) try: # Windows 系统字体路径 font_title = ImageFont.truetype("simhei.ttf", 100) # 黑体 font_sub = ImageFont.truetype("simhei.ttf", 40) font_body = ImageFont.truetype("simhei.ttf", 35) font_reward = ImageFont.truetype("simhei.ttf", 60) except IOError: # 如果找不到黑体,使用默认字体(效果会打折,但能运行) font_title = ImageFont.load_default() font_sub = font_body = font_reward = font_title # 3. 绘制文本内容 # 标题: 重大通缉犯 title = "重大通缉犯" bbox = draw.textbbox((0, 0), title, font=font_title) text_width = bbox[2] - bbox[0] draw.text(((width - text_width) / 2, 60), title, fill=accent_color, font=font_title) # 4. 绘制空白人物图像框 (带阴影效果) photo_x, photo_y = 150, 220 photo_w, photo_h = 500, 500 # 绘制阴影 shadow_offset = 10 draw.rectangle([photo_x + shadow_offset, photo_y + shadow_offset, photo_x + photo_w + shadow_offset, photo_y + photo_h + shadow_offset], fill=(0, 0, 0)) # 绘制相框 draw.rectangle([photo_x, photo_y, photo_x + photo_w, photo_y + photo_h], outline=border_color, width=8, fill=(30, 30, 30)) # 框内提示文字 hint = "[ 目标图像 ]" bbox_hint = draw.textbbox((0, 0), hint, font=font_sub) hint_w = bbox_hint[2] - bbox_hint[0] draw.text((photo_x + (photo_w - hint_w) / 2, photo_y + (photo_h - 40) / 2), hint, fill=(100, 100, 100), font=font_sub) # 5. 绘制悬赏与罪行 reward_y = 760 reward_text = "悬赏: 3000 钻石" bbox_r = draw.textbbox((0, 0), reward_text, font=font_reward) r_width = bbox_r[2] - bbox_r[0] draw.text(((width - r_width) / 2, reward_y), reward_text, fill=accent_color, font=font_reward) crime_y = 860 crime_text = "罪行: 杀死收割者阵营 300 名玩家" bbox_c = draw.textbbox((0, 0), crime_text, font=font_body) c_width = bbox_c[2] - bbox_c[0] draw.text(((width - c_width) / 2, crime_y), crime_text, fill=text_color, font=font_body) # 6. 保存图像 img.save("Wanted_Poster.png") print("通缉令已成功生成: Wanted_Poster.png") if __name__ == "__main__": create_wanted_poster()