关于 image-fetcher
image-fetcher 是一款供 Claude 使用的技能,可从 URL 单张或批量下载图片。它能识别常见图片格式,并将文件保存以供嵌入文档等用途。
主要功能
- 01通过 URL 下载单张图片
- 02批量下载文本或 JSON 中的 URL
- 03根据服务器响应识别图片格式
- 04返回保存路径和下载结果
- 05自动创建缺失的输出目录
适用场景
- 01下载图片并嵌入文档
- 02将多张网络图片保存为图库
- 03从网站获取徽标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ interstellar-code/ claud-skills --skill image-fetcher安装后在 Claude Code 中输入/image-fetcher确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
requirements.txtscripts/fetch_image.pyfetch_images_batch.py详细介绍
图片抓取工具
此工具支持多种图片格式和批量下载功能,可让 Claude 从互联网抓取并下载图片。
何时使用此工具
在用户请求以下操作时使用此工具:
- 从指定 URL 下载图片
- 从网上抓取图片并嵌入文档
- 将互联网来源的图片保存到本地
- 批量下载多张图片
- 转换或处理需要先下载的图片
支持的图片格式
此工具会自动检测并处理以下格式:
- JPG/JPEG
- PNG
- GIF
- WebP
- BMP
- SVG
- ICO
- TIFF/TIF
核心工作流
下载单张图片
从 URL 下载单张图片:
python scripts/fetch_image.py <image_url> [output_directory] [filename]
参数:
image_url(必填):要下载的图片 URLoutput_directory(可选):保存图片的目录(默认为当前目录)filename(可选):保存图片的自定义文件名(默认为 URL 中的文件名)
示例:
# Basic download to current directory
python scripts/fetch_image.py https://example.com/photo.jpg
# Download to specific directory
python scripts/fetch_image.py https://example.com/photo.jpg ./downloads
# Download with custom filename
python scripts/fetch_image.py https://example.com/photo.jpg ./downloads myimage.jpg
批量下载图片
从 URL 列表下载多张图片:
python scripts/fetch_images_batch.py <urls_file> [output_directory]
输入文件格式:
- 每行包含一个 URL 的文本文件
- 包含 URL 数组的 JSON 文件:
["url1", "url2", ...]
示例:
# Download from text file
python scripts/fetch_images_batch.py urls.txt
# Download to specific directory
python scripts/fetch_images_batch.py urls.json ./images
# Create a URL list on the fly
echo -e "https://example.com/img1.jpg\nhttps://example.com/img2.png" > urls.txt
python scripts/fetch_images_batch.py urls.txt ./downloads
批处理脚本会创建 fetch_results.json 文件,其中包含每次下载的详细结果。
与 Claude 工作流集成
嵌入文档
抓取图片并嵌入文档(DOCX、PPTX 等)时:
- 将图片下载到临时位置
- 使用返回的文件路径将图片嵌入文档
- 如有需要,清理临时文件
# Download image
python scripts/fetch_image.py https://example.com/chart.png /home/claude/temp
# The script outputs the full path which can be used for embedding
# Example output: /home/claude/temp/chart.png
在聊天中显示
下载图片并在聊天中显示时:
- 将图片下载到
/mnt/user-data/outputs/目录 - 向用户提供已下载图片的链接
python scripts/fetch_image.py https://example.com/image.jpg /mnt/user-data/outputs
搜索集成
与网页搜索结合使用时:
- 使用 web_search 工具搜索图片
- 从搜索结果中提取图片 URL
- 使用此工具下载图片
错误处理
脚本会处理常见情况:
- 无效 URL
- 网络超时
- 不支持的格式
- 权限错误
- 目录不存在(自动创建)
下载失败时会显示清晰的错误消息。
输出信息
每次成功下载都会提供:
- 保存文件的完整路径
- 文件大小(KB)
- 服务器返回的 Content-Type
- 成功确认信息
最佳实践
- 尝试下载前务必验证 URL
- 多张图片使用批量下载以提高效率
- 指定输出目录,以便妥善整理下载内容
- 检查文件扩展名——如果 URL 不包含扩展名,脚本会根据响应标头自动检测格式
- 妥善处理错误——告知用户下载失败的情况
常见用例
用例 1:将网络图片嵌入演示文稿
# User: "Add this chart to my presentation: https://data.com/chart.png"
python scripts/fetch_image.py https://data.com/chart.png /home/claude/temp
# Then use the path to embed in PPTX
用例 2:根据 URL 创建图片库
# User: "Download these product images and save them"
# Create urls.txt with image URLs
python scripts/fetch_images_batch.py urls.txt /mnt/user-data/outputs/gallery
用例 3:下载 Logo 用于品牌展示
# User: "Get the company logo from their website"
python scripts/fetch_image.py https://company.com/logo.svg /home/claude/assets logo.svg
技术说明
- 使用
requests库,并设置适当的标头以避免被拦截 - 以流式方式处理大型文件,提高内存使用效率
- 每次下载超时时间为 30 秒
- 自动检测 Content-Type 并映射扩展名
- 如果输出目录不存在,会自动创建
评论
支持 Markdown