Smart Image Loader
Quick Start
When a user asks to display an image:
- 1. Check if input is a URL or local path
- URLs start with
http:// or
https://
- Local paths are file paths in the workspace
- 2. For URLs:
- Download the image to a temporary location using the Python script
- Use
read tool to display the image
- Clean up the temporary file afterward
- 3. For local files:
- Verify the file exists (relative to workspace or absolute path)
- Use
read tool directly to display the image
Usage Examples
User says: "Show me this image: https://example.com/photo.jpg"
- 1. Run: INLINECODE4
- Script downloads to temp: INLINECODE5
- Use
read tool on: INLINECODE7 - Clean up: Delete the temp file
User says: "Display ./images/logo.png"
- 1. Run: INLINECODE8
- Script verifies file exists
- Use
read tool on: /home/node/clawd/images/logo.png (absolute path)
Script Usage
CODEBLOCK0
Arguments
| Argument | Description |
|---|
| INLINECODE11 | Either a local file path (relative or absolute) or a URL |
Output Format
The script returns a JSON-like output with:
- -
Status: SUCCESS or FAILED - INLINECODE13 : url or local
- INLINECODE14 : Local path for the
read tool - INLINECODE16 : Status description
- INLINECODE17 : true if temp file should be deleted
Examples
CODEBLOCK1
Workflow Decision Tree
CODEBLOCK2
Cleanup Guidelines
- - URL downloads: Always clean up temporary files after displaying
- Local files: No cleanup needed (files remain in workspace)
- Use
exec with rm <file_path> for cleanup
Image Formats Supported
- - JPEG (.jpg, .jpeg)
- PNG (.png)
- GIF (.gif)
- WebP (.webp)
- BMP (.bmp)
Error Handling
| Scenario | Action |
|---|
| URL download fails | Report error to user |
| Local file not found |
Report error to user |
| Invalid input | Show usage instructions |
智能图片加载器
快速开始
当用户要求显示图片时:
- 1. 检查输入是URL还是本地路径
- URL以http://或https://开头
- 本地路径是工作区中的文件路径
- 2. 对于URL:
- 使用Python脚本将图片下载到临时位置
- 使用read工具显示图片
- 之后清理临时文件
- 3. 对于本地文件:
- 验证文件是否存在(相对于工作区或绝对路径)
- 直接使用read工具显示图片
使用示例
用户说: 给我看这张图片:https://example.com/photo.jpg
- 1. 运行:python3 scripts/smartimageloader.py https://example.com/photo.jpg
- 脚本下载到临时目录:/tmp/dir/photo.jpg
- 在/tmp/dir/photo.jpg上使用read工具
- 清理:删除临时文件
用户说: 显示./images/logo.png
- 1. 运行:python3 scripts/smartimageloader.py ./images/logo.png
- 脚本验证文件是否存在
- 在/home/node/clawd/images/logo.png(绝对路径)上使用read工具
脚本使用
bash
python3 scripts/smartimageloader.py <图片路径或URL>
参数
| 参数 | 描述 |
|---|
| 图片路径或URL | 本地文件路径(相对或绝对)或URL |
输出格式
脚本返回类似JSON的输出,包含:
- - Status:SUCCESS或FAILED
- Type:url或local
- File Path:供read工具使用的本地路径
- Message:状态描述
- Cleanup Needed:如果需要删除临时文件则为true
示例
bash
URL示例
python3 scripts/smart
imageloader.py https://example.com/image.jpg
输出:下载到/tmp/xyz/image.jpg,在该路径上使用read工具
本地文件示例(相对路径)
python3 scripts/smart
imageloader.py ./photos/vacation.jpg
输出:文件位于/home/node/clawd/photos/vacation.jpg
本地文件示例(绝对路径)
python3 scripts/smart
imageloader.py /home/node/clawd/downloads/graphic.png
输出:文件位于/home/node/clawd/downloads/graphic.png
工作流程决策树
用户要求显示图片
|
v
是否为URL?(http://或https://)
|
+----+---------------------------+
| |
是 否
| |
v v
下载到临时目录 文件是否存在?
| |
v +-----+-----+
使用read工具 | |
| 是 否
v |
清理临时文件 v
使用read工具
|
v
完成(无需清理)
清理指南
- - URL下载:显示后始终清理临时文件
- 本地文件:无需清理(文件保留在工作区中)
- 使用exec配合rm <文件路径>进行清理
支持的图片格式
- - JPEG(.jpg, .jpeg)
- PNG(.png)
- GIF(.gif)
- WebP(.webp)
- BMP(.bmp)
错误处理
| 场景 | 操作 |
|---|
| URL下载失败 | 向用户报告错误 |
| 本地文件未找到 |
向用户报告错误 |
| 无效输入 | 显示使用说明 |