You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python生成类似Sherlock工具风格的图像?

关于生成Sherlock工具风格图像的问题解答

是否需要专门工具

不需要使用独立的专用工具,仅靠Python生态的常用第三方库就能实现完全匹配风格的图像,甚至如果需求简单,直接对Sherlock的终端输出截图也可以得到符合要求的结果。

Python实现方案

Sherlock工具的输出图像核心特征是黑底、高对比亮青/亮绿文字、等宽字体、带ASCII艺术字头部、分模块展示扫描结果,用以下工具链即可实现:

  • 核心绘图用Pillow库,负责画布创建、文字渲染、图片导出
  • 可选使用pyfiglet库快速生成ASCII艺术字头部,省去手动拼接艺术字的步骤

最简实现示例代码

from PIL import Image, ImageDraw, ImageFont
import pyfiglet

# 基础样式配置,完全匹配Sherlock默认风格
BG_COLOR = (0, 0, 0)  # 纯黑背景
TEXT_COLOR = (0, 255, 200)  # 亮青色文字,和Sherlock默认输出一致
FONT_SIZE = 14
# 替换为你本地的等宽字体路径,Windows可填consola.ttf,Linux可填对应系统的等宽字体路径
FONT_PATH = "consola.ttf"

# 生成Sherlock风格的文本内容
ascii_header = pyfiglet.figlet_format("Sherlock", font="slant")
content_lines = [
    ascii_header,
    "=" * 60,
    "[+] Scanning target: test_user",
    "[+] Found 9 matches across 42 platforms",
    "=" * 60,
    "[+] Instagram: https://instagram.com/test_user",
    "[+] Twitter: https://twitter.com/test_user",
    "[+] GitHub: https://github.com/test_user"
]
content = "\n".join(content_lines)

# 计算画布尺寸
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
lines = content.split("\n")
max_line_width = max(font.getbbox(line)[2] for line in lines)
total_height = sum(font.getbbox(line)[3] for line in lines) + 20  # 上下预留10px边距

# 绘制图像
img = Image.new("RGB", (max_line_width + 20, total_height), BG_COLOR)
draw = ImageDraw.Draw(img)
y_offset = 10
for line in lines:
    draw.text((10, y_offset), line, fill=TEXT_COLOR, font=font)
    y_offset += font.getbbox(line)[3]

# 导出结果
img.save("sherlock_output.png")

内容的提问来源于stack exchange,提问作者Newbula

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 22:09:03