smart-image-loader
Scanned@tingwei1123
npx machina-cli add skill @tingwei1123/smart-image-loader --openclawSmart Image Loader
Quick Start
When a user asks to display an image:
-
Check if input is a URL or local path
- URLs start with
http://orhttps:// - Local paths are file paths in the workspace
- URLs start with
-
For URLs:
- Download the image to a temporary location using the Python script
- Use
readtool to display the image - Clean up the temporary file afterward
-
For local files:
- Verify the file exists (relative to workspace or absolute path)
- Use
readtool directly to display the image
Usage Examples
User says: "Show me this image: https://example.com/photo.jpg"
- Run:
python3 scripts/smart_image_loader.py https://example.com/photo.jpg - Script downloads to temp:
/tmp/dir/photo.jpg - Use
readtool on:/tmp/dir/photo.jpg - Clean up: Delete the temp file
User says: "Display ./images/logo.png"
- Run:
python3 scripts/smart_image_loader.py ./images/logo.png - Script verifies file exists
- Use
readtool on:/home/node/clawd/images/logo.png(absolute path)
Script Usage
python3 scripts/smart_image_loader.py <image_path_or_url>
Arguments
| Argument | Description |
|---|---|
image_path_or_url | Either a local file path (relative or absolute) or a URL |
Output Format
The script returns a JSON-like output with:
Status: SUCCESS or FAILEDType: url or localFile Path: Local path for thereadtoolMessage: Status descriptionCleanup Needed: true if temp file should be deleted
Examples
# URL example
python3 scripts/smart_image_loader.py https://example.com/image.jpg
# Output: Downloads to /tmp/xyz/image.jpg, use read tool on that path
# Local file example (relative)
python3 scripts/smart_image_loader.py ./photos/vacation.jpg
# Output: File found at /home/node/clawd/photos/vacation.jpg
# Local file example (absolute)
python3 scripts/smart_image_loader.py /home/node/clawd/downloads/graphic.png
# Output: File found at /home/node/clawd/downloads/graphic.png
Workflow Decision Tree
User asks to display an image
|
v
Is it a URL? (http:// or https://)
|
+----+---------------------------+
| |
YES NO
| |
v v
Download to temp Does file exist?
| |
v +-----+-----+
Use read tool | |
| YES NO
v |
Cleanup temp file v
Use read tool
|
v
Done (no cleanup)
Cleanup Guidelines
- URL downloads: Always clean up temporary files after displaying
- Local files: No cleanup needed (files remain in workspace)
- Use
execwithrm <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 |
Overview
Smart image loader handles both web URLs and local workspace files. It downloads URL images to a temporary location, then displays them with the read tool and cleans up afterward. This makes viewing images seamless whether they come from the web or from local storage.
How This Skill Works
When asked to display an image, it checks if the input is a URL or a local path. For URLs, it downloads the image to a temporary file, uses the read tool to display it, and then removes the temporary file. For local files, it verifies the path exists and uses the read tool directly.
When to Use It
- User asks to display an image from a web URL (http or https).
- User asks to display an image located in the workspace using a relative path.
- User provides an absolute file path to an image and wants to view it.
- You need to display a URL image and ensure temporary files are cleaned up after viewing.
- The user provides an image path that is invalid or not found and requires an error response.
Quick Start
- Step 1: Run the script with the image path or URL: python3 scripts/smart_image_loader.py <image_path_or_url>
- Step 2: If a URL is provided, the script downloads to a temporary path (e.g., /tmp/xyz/image.jpg) and you should use read on that path
- Step 3: If a local file is provided, the script verifies existence and you should use read directly; any temp file created for URLs will be cleaned up automatically
Best Practices
- Determine input type by URL scheme first (http/https) or local path.
- Validate that local paths exist before attempting to read them.
- Use the read tool to display images after either download or verification.
- If a URL is used, ensure temporary files are cleaned up promptly after display.
- Support common formats (JPEG, PNG, GIF, WEBP, BMP) and clearly report unsupported types.
Example Use Cases
- Show me this image: https://example.com/photo.jpg
- Display ./images/logo.png
- Preview image at /home/node/clawd/images/hero.jpg
- Render image from https://cdn.example.org/banner.webp in chat
- Access image located in workspace: assets/banner.gif