unsplash
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUnsplash Photo Search
Unsplash 图片搜索
Search and fetch high-quality photos from Unsplash with automatic attribution.
从Unsplash搜索并获取高质量图片,支持自动生成署名。
Quick Start
快速开始
bash
undefinedbash
undefinedSearch for photos
搜索图片
./scripts/search.sh "sunset beach"
./scripts/search.sh "sunset beach"
Get random photos
获取随机图片
./scripts/random.sh "nature" 3
./scripts/random.sh "nature" 3
Track download (when user downloads)
跟踪下载(当用户下载图片时调用)
./scripts/track.sh PHOTO_ID
undefined./scripts/track.sh PHOTO_ID
undefinedSetup (Interactive)
交互式设置
IMPORTANT: If the script returns , handle it interactively:
UNSPLASH_ACCESS_KEY not set-
Ask the user: "I need an Unsplash API key to search for photos. You can get a free key at https://unsplash.com/developers - do you have one?"
-
Wait for the user to provide their key
-
Save the key toin the project root:
.envbashecho "UNSPLASH_ACCESS_KEY=<user_provided_key>" >> .env -
Re-run the original search/random command
The skill automatically loads from the project root on each run.
.env重要提示: 如果脚本返回,请按以下交互式流程处理:
UNSPLASH_ACCESS_KEY not set-
询问用户:"我需要Unsplash API密钥才能搜索图片,你可以在https://unsplash.com/developers 免费获取密钥,请问你有密钥吗?"
-
等待用户提供密钥
-
将密钥保存到项目根目录的文件中:
.envbashecho "UNSPLASH_ACCESS_KEY=<user_provided_key>" >> .env -
重新运行原来的搜索/随机图片命令
本工具每次运行时会自动加载项目根目录下的文件。
.envOperations
功能操作
1. Search Photos
1. 搜索图片
Find photos by keyword with optional filters.
bash
./scripts/search.sh QUERY [PAGE] [PER_PAGE] [ORDER_BY] [ORIENTATION] [COLOR]Parameters:
- (required): Search keyword(s)
QUERY - (optional, default: 1): Page number for pagination
PAGE - (optional, default: 10): Results per page (1-30)
PER_PAGE - (optional, default: "relevant"): Sort order ("relevant" or "latest")
ORDER_BY - (optional): Filter by orientation ("landscape", "portrait", "squarish")
ORIENTATION - (optional): Filter by color ("black_and_white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue")
COLOR
Examples:
bash
undefined按关键词查找图片,支持可选过滤条件。
bash
./scripts/search.sh QUERY [PAGE] [PER_PAGE] [ORDER_BY] [ORIENTATION] [COLOR]参数说明:
- (必填):搜索关键词
QUERY - (可选,默认值:1):分页页码
PAGE - (可选,默认值:10):每页返回结果数(1-30)
PER_PAGE - (可选,默认值:"relevant"):排序方式("relevant"相关度 / "latest"最新)
ORDER_BY - (可选):按图片方向过滤("landscape"横版 / "portrait"竖版 / "squarish"方形)
ORIENTATION - (可选):按颜色过滤("black_and_white"黑白 / "black"黑 / "white"白 / "yellow"黄 / "orange"橙 / "red"红 / "purple"紫 / "magenta"洋红 / "green"绿 / "teal"青 / "blue"蓝)
COLOR
示例:
bash
undefinedBasic search
基础搜索
./scripts/search.sh "mountain landscape"
./scripts/search.sh "mountain landscape"
Search with filters
带过滤条件的搜索
./scripts/search.sh "sunset" 1 5 latest landscape
./scripts/search.sh "sunset" 1 5 latest landscape
Search by color
按颜色搜索
./scripts/search.sh "flower" 1 10 relevant portrait red
undefined./scripts/search.sh "flower" 1 10 relevant portrait red
undefined2. Random Photos
2. 随机图片
Get random photos with optional filtering.
bash
./scripts/random.sh [QUERY] [COUNT] [ORIENTATION]Parameters:
- (optional): Topic/keyword to filter random photos
QUERY - (optional, default: 1): Number of photos (1-30)
COUNT - (optional): Filter by orientation ("landscape", "portrait", "squarish")
ORIENTATION
Examples:
bash
undefined获取随机图片,支持可选过滤条件。
bash
./scripts/random.sh [QUERY] [COUNT] [ORIENTATION]参数说明:
- (可选):用于过滤随机图片的主题/关键词
QUERY - (可选,默认值:1):返回图片数量(1-30)
COUNT - (可选):按图片方向过滤("landscape"横版 / "portrait"竖版 / "squarish"方形)
ORIENTATION
示例:
bash
undefinedSingle random photo
获取单张随机图片
./scripts/random.sh
./scripts/random.sh
Random photos by topic
按主题获取随机图片
./scripts/random.sh "architecture" 5
./scripts/random.sh "architecture" 5
Random landscape photos
获取横版随机自然风景图
./scripts/random.sh "nature" 3 landscape
undefined./scripts/random.sh "nature" 3 landscape
undefined3. Track Download
3. 下载跟踪
Track when a user downloads a photo (required by Unsplash API guidelines).
bash
./scripts/track.sh PHOTO_IDWhen to call:
- When user actually downloads/saves the image file
- NOT when just viewing or displaying the photo
- Helps photographers get credit for downloads
Example:
bash
./scripts/track.sh "abc123xyz"跟踪用户的图片下载行为(Unsplash API规范要求)。
bash
./scripts/track.sh PHOTO_ID调用时机:
- 仅当用户实际下载/保存图片文件时调用
- 仅查看或展示图片时不要调用
- 该操作有助于摄影师获得下载量统计的相应权益
示例:
bash
./scripts/track.sh "abc123xyz"Output Format
输出格式
All operations return JSON with complete photo information:
json
{
"id": "abc123xyz",
"description": "A beautiful sunset over mountains",
"alt_description": "orange sunset behind mountain range",
"urls": {
"raw": "https://...",
"full": "https://...",
"regular": "https://...",
"small": "https://...",
"thumb": "https://..."
},
"width": 6000,
"height": 4000,
"color": "#f3a460",
"blur_hash": "L8H2#8-;00~q4n",
"photographer_name": "Jane Smith",
"photographer_username": "janesmith",
"photographer_url": "https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral",
"photo_url": "https://unsplash.com/photos/abc123xyz?utm_source=claude_skill&utm_medium=referral",
"attribution_text": "Photo by Jane Smith on Unsplash",
"attribution_html": "Photo by <a href=\"https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral\">Jane Smith</a> on <a href=\"https://unsplash.com/?utm_source=claude_skill&utm_medium=referral\">Unsplash</a>"
}所有操作都会返回包含完整图片信息的JSON:
json
{
"id": "abc123xyz",
"description": "A beautiful sunset over mountains",
"alt_description": "orange sunset behind mountain range",
"urls": {
"raw": "https://...",
"full": "https://...",
"regular": "https://...",
"small": "https://...",
"thumb": "https://..."
},
"width": 6000,
"height": 4000,
"color": "#f3a460",
"blur_hash": "L8H2#8-;00~q4n",
"photographer_name": "Jane Smith",
"photographer_username": "janesmith",
"photographer_url": "https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral",
"photo_url": "https://unsplash.com/photos/abc123xyz?utm_source=claude_skill&utm_medium=referral",
"attribution_text": "Photo by Jane Smith on Unsplash",
"attribution_html": "Photo by <a href=\"https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral\">Jane Smith</a> on <a href=\"https://unsplash.com/?utm_source=claude_skill&utm_medium=referral\">Unsplash</a>"
}Image URLs
图片URL说明
The object contains different sizes:
urls- raw: Original unprocessed image
- full: Full resolution (max width/height: 5472px)
- regular: Web display size (1080px wide)
- small: Thumbnail (400px wide)
- thumb: Small thumbnail (200px wide)
Recommended: Use for most web content (best quality/size balance).
urls.regularurls- raw:原始未处理图片
- full:全分辨率图片(最大宽/高:5472px)
- regular:网页展示尺寸(宽1080px)
- small:缩略图(宽400px)
- thumb:小缩略图(宽200px)
推荐用法: 大多数网页内容使用即可,能实现画质和文件大小的最佳平衡。
urls.regularAttribution Requirements
署名要求
CRITICAL: Unsplash requires attribution for all image usage.
关键提醒: Unsplash要求所有使用其图片的场景都必须提供署名。
Always Include Attribution
必须包含署名
When presenting photos to users, you MUST include one of:
-
attribution_text (for plain text contexts):
Photo by Jane Smith on Unsplash -
attribution_html (for HTML/web contexts):html
Photo by <a href="...">Jane Smith</a> on <a href="...">Unsplash</a>
向用户展示图片时,你必须提供以下任意一种署名信息:
-
attribution_text(适用于纯文本场景):
Photo by Jane Smith on Unsplash -
attribution_html(适用于HTML/网页场景):html
Photo by <a href="...">Jane Smith</a> on <a href="...">Unsplash</a>
Placement Guidelines
放置规范
- Place attribution near the image (below or in caption)
- Make it visible and readable
- Don't remove or hide the attribution
- Attribution is required by Unsplash API terms
- 署名需放在图片附近(下方或图片说明中)
- 需清晰可见、易于阅读
- 不得移除或隐藏署名
- Unsplash API条款要求必须提供署名
Why Attribution Matters
署名的重要性
- Gives credit to photographers
- Required by Unsplash API terms of service
- Violating attribution can result in API access suspension
- 尊重摄影师的劳动成果,为其提供署名权益
- 是Unsplash API服务条款的强制要求
- 违反署名要求可能会导致API访问权限被暂停
Common Workflows
常见工作流
Blog Post Hero Image
博客文章头图
bash
undefinedbash
undefinedSearch for relevant image
搜索相关图片
./scripts/search.sh "technology workspace" 1 3 latest landscape
./scripts/search.sh "technology workspace" 1 3 latest landscape
Present options to user with attribution
向用户展示带署名的可选图片
User selects one
用户选中某张图片后
Display image with attribution_html in blog post
在博客文章中使用attribution_html展示图片及署名
undefinedundefinedGallery of Random Images
随机图片画廊
bash
undefinedbash
undefinedGet variety of images
获取多样化的图片
./scripts/random.sh "travel" 10
./scripts/random.sh "travel" 10
Display all images with their attributions
展示所有图片及对应的署名信息
undefinedundefinedSpecific Color Palette
匹配特定配色
bash
undefinedbash
undefinedSearch for images matching brand colors
搜索符合品牌配色的图片
./scripts/search.sh "abstract" 1 5 latest "" blue
undefined./scripts/search.sh "abstract" 1 5 latest "" blue
undefinedError Handling
错误处理
Missing API Key:
ERROR: UNSPLASH_ACCESS_KEY not set→ See "Setup (Interactive)" section above. Ask user for key, save to , and retry.
.envRate Limit Exceeded:
ERROR: Rate limit exceeded (50/hour in demo mode)Wait an hour or use production credentials with higher limits.
Invalid API Key:
ERROR: Invalid API keyCheck that your API key is correct.
No Results:
json
[]Empty array returned if no photos match search criteria.
缺少API密钥:
ERROR: UNSPLASH_ACCESS_KEY not set→ 参考上方“交互式设置”章节,向用户索要密钥,保存到后重试。
.env超出速率限制:
ERROR: Rate limit exceeded (50/hour in demo mode)等待1小时,或者使用速率限制更高的生产环境凭证。
API密钥无效:
ERROR: Invalid API key检查你填写的API密钥是否正确。
无匹配结果:
json
[]如果没有符合搜索条件的图片,会返回空数组。
Dependencies
依赖
Required tools (standard on macOS/Linux):
- - Shell interpreter
bash - - HTTP client
curl - - JSON processor
jq
Install jq if missing:
bash
undefined需要的工具(macOS/Linux系统默认预装):
- - Shell解释器
bash - - HTTP客户端
curl - - JSON处理工具
jq
如果缺少jq可执行以下命令安装:
bash
undefinedmacOS
macOS
brew install jq
brew install jq
Ubuntu/Debian
Ubuntu/Debian
sudo apt-get install jq
undefinedsudo apt-get install jq
undefinedRate Limits
速率限制
- Demo mode: 50 requests/hour
- Production mode: 5,000 requests/hour
Production mode requires:
- Creating an Unsplash app
- Getting app approval from Unsplash
- Using your production access key
- 演示模式:每小时50次请求
- 生产模式:每小时5000次请求
使用生产模式需要:
- 创建Unsplash应用
- 提交应用给Unsplash审核通过
- 使用你的生产环境访问密钥
Best Practices
最佳实践
- Use specific search terms - More specific queries yield better results
- Filter by orientation - Match your layout needs (landscape/portrait)
- Always include attribution - Required by API terms
- Use regular size for web - Best quality/performance balance
- Track actual downloads - Only call track.sh when user downloads
- Cache results - Don't re-search for the same keywords
- Respect rate limits - Monitor usage in demo mode
- 使用具体的搜索词:越精准的查询返回的结果匹配度越高
- 按图片方向过滤:匹配你的布局需求(横版/竖版)
- 始终提供署名:API条款的强制要求
- 网页使用regular尺寸:画质和加载性能的最佳平衡
- 仅跟踪实际下载行为:仅当用户下载图片时调用track.sh
- 缓存结果:相同关键词不要重复搜索
- 遵守速率限制:演示模式下注意监控请求用量
More Examples
更多示例
See detailed usage patterns in:
examples/usage-examples.md查看详细使用场景参考:
examples/usage-examples.mdTroubleshooting
故障排查
Scripts not executable:
bash
chmod +x scripts/*.shjq not found:
bash
brew install jq # macOSAPI errors:
- Check internet connection
- Verify API key is set correctly
- Check rate limit hasn't been exceeded
- Ensure photo_id is valid (for track.sh)
脚本无执行权限:
bash
chmod +x scripts/*.sh找不到jq命令:
bash
brew install jq # macOSAPI错误:
- 检查网络连接
- 确认API密钥已正确设置
- 检查是否超出速率限制
- 确认photo_id有效(调用track.sh时)
Links
相关链接
- Unsplash API Documentation: https://unsplash.com/documentation
- Get API Key: https://unsplash.com/developers
- Unsplash Guidelines: https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines
- Unsplash API文档:https://unsplash.com/documentation
- 获取API密钥:https://unsplash.com/developers
- Unsplash使用规范:https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines